Microsoft Service Fabric for the microservices framework

Source: Internet
Author: User
Tags hosting webhost docker swarm docker registry azure load balancer

Software & Components for common microservices architectures:

Docker (Mature application)

Spring Boot% Spring Cloud (technology trends)

Service Fabric (behind a rising star is the driver of Microsoft Cloud)

The four common microservices architectures are Zeroc Icegrid, Spring Cloud, Message Queuing and Docker Swarm.

The actual production is mostly a combination of pattern applications such as best practice Spring Cloud+docker.

MicroServices Features-Continuous integration (JENKINS,SNAP-CI), Build (Maven,gradle), Deployment (Docker), continuous Delivery (Jenkins), log aggregation (Elk,splunk), Operations (monitoring warning Zabbix,nagios)

Microsoft's official blog for Azure service Fabric released a blog service fabric. NET SDK goes open source on 2017.3.24, describing the community's highest-calling Service fabric open source And the current situation, when the. NET SDK part of the service fabric was open source, the community has been looking forward to the formal open source service fabric, after a year of long wait, March 14, 2018 Microsoft finally open source service fabric, and is to Open source under MIT license, announced in the official blog Https://blogs.msdn.microsoft.com/azureservicefabric/2018/03/14/service-fabric-is-going-open-source.

At present, Microsoft's Open source address on Github is https://github.com/Microsoft/service-fabric, the current code is built for Linux service fabric, running basic tests, problems can be submitted Issue and PR, the Windows build environment and the full CI environment have not yet migrated. Internal services for service Fabric have been developed within Windows for almost 10 years, most of which are internal Microsoft platforms, such as the Office365,azure Stack platform, This means that we have nearly a decade of internal Microsoft tools can be migrated before the migration and process refinement, gradually all open source, all development in the future in open source mode for development work.

Service Fabric Basic Concepts: Node, application, service, Partition/replicas

Azure Service Fabric is a distributed system platform that makes it easy for users to easily package, deploy, and manage scalable, reliable microservices and containers. Developers and administrators do not need to address complex infrastructure issues, just focus on implementing demanding, mission-critical workloads-those that are scalable, reliable, and manageable.

This section introduces the basic concepts of azure service fabric and the working mechanisms of related components, including micro Service, node type, node, and so on. Although the name is Azure Service fabric but it can be applied to more platforms than the Azure platform itself, we will describe the service fabric's working form on each platform in the usage scenario for the next section.

Microsoft Azure Service Fabric is a framework that Microsoft has developed to support highly available, highly scalable cloud services, and the core part is a distributed system platform for building scalable and reliable applications. Support the creation of stateless and stateful microservices while enabling the encapsulation of deployable code, scaling them through cloud platforms to address high complexity, low latency, and data-intensive situations. Developers and system administrators can avoid complex infrastructure problems and devote more effort to the implementation of the application being built.

Micro-Service Microservice

Before introducing service fabric, I had to mention the idea of microservices. Because the development process using service fabric is the design and development process of microservices. With service fabric, you only need to consider the functionality of developing microservices without having to worry too much about post-deployment scalability and usability issues that can be handed over to service fabric for you.

The idea of microservices is to decouple complex monolithic applications into multiple independent services, and in the event of a constant function, multiple manageable services can communicate with each other through the agreed interface. This approach provides a modular solution for features that are difficult to implement with single-piece coding. Because a single service can be easier to develop and maintain. This architecture allows each individual service to have a dedicated team to develop, each team can choose their own good development technology, through the contract interface to achieve mutual communication. Each service can be implemented, tested, deployed, and upgraded independently, and developers no longer need to worry about the impact of other service deployments on the service. The AB test accelerates deployment, enabling continuous integration and continuous deployment. All microservices serve as a whole, while individual microservices can scale independently to maximize the resource utilization of the server based on their own requirements for resources.

Back in service fabric, a service fabric-developed application consists of several services, each of which can be individually modified, extended, and managed as an individual, and managed in a complete application. Service fabric is designed to simplify the process of building complex applications in a microservices way.

Cluster cluster

A cluster is a set of virtual or physical hosts that are connected over a network, and your microservices are deployed in a cluster, and the size of the cluster can be extended to thousands of hosts.

Nodes node

A machine or VM in a cluster is called node, and each node is assigned a name (string string). Node has other properties, such as the Location attribute placement properties. Each machine or VM can have a self-booting Windows system service FabricHost.exe, which executes two other programs as the system boots: Fabric.exe and FabricGateway.exe, the two programs form a complete node. For testing purposes, it is sometimes possible to have more than one node on a single machine by running multiple instances of Fabric.exe and FabricGateway.exe.

All node in a cluster is equal to each other and can communicate directly with each other. Node can be hosted in a Windows-based Docker container, on-premises servers, in other public and private clouds, in addition to being hosted on a physical host or VM, and we'll cover this in more detail in the context of subsequent service fabric usage scenarios.

Application application:application type and service type

A service Fabric application (application) is a collection of services, where one service is a unit that provides the specified functionality for application. You will build a service fabric application by defining a application type and a corresponding number of service type. When application is deployed to service Fabric cluster, these types are initialized accordingly to application instances and service instances. This is similar to our oo thinking.

The application type and named Application:application type contain a set of service type, corresponding to the services fabric application (application) in the preceding section ( Service) collection. The name and version of the application type are defined in the Applicationmanifest.xml file. At deployment time, the Applicationmanifest.xml will be copied to the service fabric's image store. Initializes an instance of application by creating a named application in cluster. Named application is named by the form "Fabric:/mynamedapp".

The name and version of the Service type and named Service:service type are defined in the Servicemanifest.xml file. After you create the good one named application, you can create a named service. For example, if you create a "MyDatabase" Named service in the "Mynamedapp" Named application, the name service is named "Fabric:/mynamedapp/mydatabase".

partition partitions and Replication replicas

A Service can contain multiple partitions partition,service fabric distributes work to different Service instances by using partitioning as an extension mechanism.

A partition partition can contain one or more replication replicas. Service fabric uses replication to achieve availability. A partition can have a primary replication and multiple replication, and the state between multiple replications can be automatically synchronized. When there is an error in the primary replication, one of them is automatically promoted to primary replication from replication to ensure the availability of the system. The number of copies will then be restored to normal levels, ensuring sufficient redundancy from replication.

Run the Spring boot microservices using visual Studio+service Fabric

Service fabric is a Microsoft-provided MicroServices management framework that has been validated by multiple products such as Microsoft Cosmos Db.

The Service Fabric Official documentation provides only the development deployment scenarios for visual Studio +. Net + C # and the deployment scenarios for Linux + Eclipse + java, but without the visual Studio+eclipse+java deployment approach, by touching and documentation, and found that Microsoft offered such a way that Microsoft was much more open than before.

1. First create a service fabric project in Visual Studio,

2. Select the Guest executable file, enter the name of the first micro-service, select the file directory where the executable jar package is located, Work folder is selected as CodeBase,

3. In the VS Project tree, select the jar package and copy/paste the Java Runtime Environment package into the code directory.

4. Open "Servicemanifest.xml", change the following parameters,

    1. Program:this should point to java.exe the file in JRE folder is copied.
    2. Arguments:this should contain The-jar and path of the jar filename relative to Java.exe. They is arguments passed to Java.exe when it starts.
    3. Workingfolder:this should be CodeBase.
    4. Endpoint:name a Endpoint and provide protocol as HTTP and Port no (8080) along with type (input)

5. Click the Start button to deploy this microservices to the local service Fabric cluster.

"Case in depth" with service fabric hosting eshop on Containers

From modularity to MicroServices

From Pet Shop to eshop on Container is a sample project where Microsoft shows developers the development capabilities and architectural capabilities of. NET in the path of technology evolution, and PetShop is more of a layered architecture for presenting applications, abstraction of design and communication between modules. To eshop on container more attention in architecture design and microservices, let's take a look at the architecture diagram of eshop on container

In, we can see that the backend service is divided into

    1. Identity Microservice (authentication Service)
    2. Catalog Microservice (Product Classification Service)
    3. Ordering Microservice (order service)
    4. Basket Microservice (Shopping cart service)
    5. Marketing Microservice (Marketing services)
    6. Locations Microservice (Location information Service)

In the previous layered architecture, these services were usually embodied in a module, why would they now be split into services? When we look at these services from the business scenario, we find that the peak time interval for each service, capacity planning is different, and even the most convenient and simple technology stack to implement these services may be different (of course, the powerful. NET core is omnipotent, However, different business lines in the company's technical reserves are not the same, it is possible to choose different technologies to achieve. This is because if we all integrate these modules into a program or service, we will encounter the time of Service peak expansion system capacity is difficult, either is insufficient resources, or resource surplus. For example, before snapping up the business began a half an hour ahead of the system, the system is the busiest is the login module, to start snapping time, the most busy system is the order module. Without a micro-service architecture, the resources that were prepared to be used by the login module half an hour ago will not be released to the order module in a timely manner. If all two modules use a single program architecture, it is likely that the snapping up of the business will fill up all the resources, and even other normal access to the system's user resources are occupied, causing the system to crash. In Dev/ops today, developers and architects need to think more about the impact of the hardware architecture level on program applications.

Method of hosting eshop on container microservices with service fabric One, manage Docker directly through service fabric

First we go to Azure to apply for a container registry to host the image (image) of eshop each microservices program. Create an azure Docker registry can refer to the official documentation: https:// docs.microsoft.com/zh-cn/azure/container-registry/

Now the latest version of service fabric has been able to manage the orchestration of Docker directly.

1. Create a service of type container

2. Describe the path of image in Servicemanifest.xml

<codepackage name= "Code" version= "1.0.0" >    <!--follow this link for more information about deploying Windows Containers to Service fabric:https://aka.ms/sfguestcontainers-    <EntryPoint>        <containerhost >        <ImageName>eshopsample.azurecr.io/catalog:latest</ImageName>             </ContainerHost>          </EntryPoint>    <!--Pass environment variables to your container:--       < environmentvariables>      <environmentvariable name= "httpgatewayport" value= "/> </    Environmentvariables>  </CodePackage>

This is very simple, it is OK to specify the location of the image, if the Docker image itself requires a lot of configuration information such as: Database link string, the address of other services, etc. can be configured in the Environmentvariables.

3. Configure the registry access account password, you need to configure it on the Applicationmanifest.xml

<ServiceManifestImport>    <servicemanifestref servicemanifestname= "catalogservice_pkg"  servicemanifestversion= "1.0.1"/>          <Policies>      <containerhostpolicies codepackageref= "Code" isolation= "Hyperv" >        <repositorycredentials accountname= "Youraccount" password= "xxxxxxxxxxxxx" Passwordencrypted= "false"/>        <portbinding containerport= "Up" endpointref= "Catalogservieendpoint"/>            </ContainerHostPolicies>    </Policies>  </ServiceManifestImport>

The whole process is not too complicated, just configure the catalog Microserivce the SERVICEMANIFEST.XM and applicationmanifest.xml files, we can do the other service one by one configuration in the same way, and then we can put the service The fabric configuration publish to cluster.

Service fabric automatically cluster the image on top of the configuration and runs Docker. Very simple

Method of hosting eshop on container microservices with service fabric two: Run eshop on container microservices with service fabric runtime

Service fabric itself is a development framework for microservices, and now directly supports. NET Core 2.0 so, after we have updated the SDK for service fabric, we can create. NET Core Services directly.

EShop on container code is already a molded. NET Core 2.0 code, so there is no need to rewrite the service.

1. Add the latest service Fabric SDK with NuGet.

2. Modify the Programe.cs to start the Servicefabric runtime instead of directly starting ASP. webhost

public static void Main (string[] args)        {            try            {                //Servicemanifest.xml file defines one or more service type names.                the//Registration service maps the service type name to a. NET type. //                When an instance of this service type is created in service Fabric,                an instance of the class is created in this host process.                Serviceruntime.registerserviceasync ("Catalog.api",                    context = new Catalogapi (context)). Getawaiter (). GetResult ();                ServiceEventSource.Current.ServiceTypeRegistered (Process.getcurrentprocess (). Id, typeof (Catalogapi). Name);                Prevents this host process from terminating to keep the service running.                 Thread.Sleep (timeout.infinite);            }            catch (Exception e)            {                ServiceEventSource.Current.ServiceHostInitializationFailed (e.tostring ());                throw;            }}

3. Writing

The Catalogapi class is used to start webhost

Internal sealed class Catalogapi:statelessservice {public Catalogapi (Statelessservicecontext context) : Base (context) {}///<summary>//Optional override to create listeners (like TCP, HTTP        ) for the This service instance. </summary>//<returns>the collection of listeners.</returns> protected override Ienu Merable<serviceinstancelistener> createserviceinstancelisteners () {return new serviceinstancelist Ener[] {new Serviceinstancelistener (Servicecontext = new Kestrelcommunic Ationlistener (Servicecontext, "ServiceEndpoint", (URL, listener) + = {Service                                                EventSource.Current.ServiceMessage (Servicecontext, $ "starting Weblistener on {URL}"); return new Webhostbuilder ().                  Usekestrel ()                  .                                            Configureservices (Services = Services . Addsingleton<statelessservicecontext> (Servicecontext)). Usecontentroot (Directory.GetCurrentDirectory ()).                                        Configureappconfiguration ((buildercontext, config) + = {                                        Ihostingenvironment env = buildercontext.hostingenvironment; Config. Addjsonfile ("Settings.json", Optional:false, Reloadonchange:true). Addjsonfile ($ "appsettings.{ Env.                                                                           Environmentname}.json ", Optional:true, Reloadonchange:true); })                                    . Usestartup<startup> (). Useservicefabricintegration (Listener, ServicefabricIntegrationoptions.none). Useurls (URL). Usewebroot ("Pics").                                      Build ();        }))            }; }    }

4. Write Servicemanifest.xml describing service ports, etc.

<?xml version= "1.0" encoding= "Utf-8"? ><servicemanifest name= "catalog.apipkg" version= "1.0.3" xmlns= "Http://schemas.microsoft.com/2011/01/fabric" xmlns:xsd= "Http://www.w3.org/2001/XMLSchem A "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "> <ServiceTypes> <statelessser Vicetype servicetypename= "Catalog.api"/> </ServiceTypes> <!--Code package is your service executable. --<codepackage name= "Code" version= "1.0.3" > <EntryPoint> <ExeHost> <program>c Atalog. api.exe</program> <WorkingFolder>CodePackage</WorkingFolder> </ExeHost> </entryp oint> <EnvironmentVariables> <environmentvariable name= "aspnetcore_environment" value= "development"/&G    T </EnvironmentVariables> </CodePackage> <configpackage name= "Config" version= "1.0.1"/> < Resources> <endpoints> <endpoint protocol= "http" name= "ServiceEndpoint" type= "Input" port= "5101"/> </endpoi Nts> </Resources></ServiceManifest>

5. Modify Appcationmanifest.xml to add a few service description information

Add Serviceimport section

<ServiceManifestImport>    <servicemanifestref servicemanifestname= "Catalog.apipkg" servicemanifestversion= "1.0.3"/>    <configoverrides/>  </ServiceManifestImport>

Describe the service in Defaultservice

<service name= "Catalog.api" servicednsname= "Catalog.fabric.api" >      <statelessservice servicetypename= " Catalog.api "instancecount=" [Catalog.api_instancecount] ">        <singletonpartition/>      </ Statelessservice>    </Service>

This allows us to transform the catalog service into a microservices that can be managed through service fabric. With publish, we can see that several services have been managed and orchestrated under service fabric.

Visit localhost:5100

Learn the summary of Azure Service Fabric:

    • Azure Service fabric is actually divided into two pieces: Azure and service fabric.
    • Service fabric is just a set of software distributed systems, which in theory can be used in non-azure environments. That is, a machine cluster that is not in the Azure environment is properly configured, and a distributed system can be built using service Fabric.
    • When we create azure Service fabric on the Azure portal, Azure Load Balancer is automatically created, Azure virtual machine scale Set, and azure virtual machine. This is because these components are the components and platforms that will be required to access the service fabric into the public network in an azure environment. But theoretically, if there are other products in the future, with reasonable load balancing and configuration logic, service fabric can be used as long as the server cluster can provide services for the external network.
    • Service Fabric builds on its own set of virtual concepts, including the micro Service, node type, node, and so on, which will be mentioned later. These concepts are only applicable within the scope of service fabric. For example, a micro Service can be built in C # or implemented in Java. The Node type can be either azure VMSS or a hardware physical server.
    • Service fabric helps architects decouple distributed systems and hardware. Ideally, all of the responsibilities are as follows:
      • Software developers only need a relational distributed micro-service functional logic implementation, how microservices are called through the unified interface to complete
      • Application Deployer only needs to be concerned with how to deploy microservices to individual node and consider the application's upgrade maintenance
      • The hardware architect only cares about maintaining the deployment relationship between the virtual machine and the network, and the problem with virtual machine performance is to increase the virtual machine to share the pressure

Resources

1. Micro-service framework of micro-service architecture Microsoft Servicefabric Official open Source (iii) http://baijiahao.baidu.com/s?id=1595179278058800506

2. Service Fabric https://azure.microsoft.com/zh-cn/documentation/learning-paths/service-fabric/

3. DevOps Tools Integration | Microsoft Azure https://azure.microsoft.com/zh-cn/products/devops-tool-integrations/

4, "Graphic" micro-service architecture Design _https://wenku.baidu.com/view/eb6467d10408763231126edb6f1aff00bed570a3.html

5. Micro-Service architecture and practice summary-Electronic Enthusiasts Network touch screen version http://m.elecfans.com/article/631884.html

6, micro-service architecture design-petterliu-Blog Park https://www.cnblogs.com/wintersun/p/6219259.html

7. Micro-Service practice: Migrating from a monolithic architecture to a microservices architecture 70239716

8, micro-service architecture-old _ Zhang-blog Park https://www.cnblogs.com/imyalost/p/6792724.html

This article turns from: 80696225

Microsoft Service Fabric for the microservices framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.