Exploring the application model

A service fabric application is made up of several Microservices. A Microservice is further made up of three parts:

  • Code: These are the executable binaries of the Microservice. The binaries are packaged in code package.
  • Configuration: These are the settings that can be used by your Microservices at run time. These are packaged into a configuration package.
  • Data: Any static data that is used by the Microservice is packaged in data package.

A Service Fabric application is described by a set of versioned manifests, an application manifest, and several service manifests, one each for each of the Microservices that make up the application. Let's explore the components of a Service Fabric application by navigating through the Service Fabric application package.

To package your application, right click on your Service Fabric application project and click on the Package option:

Package application

Once the application has finished packaging, open the package folder by navigating to the package location that is shown in the output window. Your application package will have a layout like that shown in the following image:

Let's discuss the various files available in your package in a bit more detail:

  • Application manifest: The application manifest is used to describe the application. It lists the services that compose it, and other parameters that are used to define how one or more services should be deployed, such as the number of instances.

In Service Fabric, an application is a unit of deployment and upgrade. An application can be upgraded as a single unit where potential failures and potential rollbacks are managed. Service Fabric guarantees that the upgrade process is either successful, or, if the upgrade fails, does not leave the application in an unknown or unstable state.

  • Service manifest: There is one service manifest for each reliable service in the application. The service manifest describes the components of a Microservice. It includes data, such as the name and type of service, and its code and configuration. The service manifest also includes some additional parameters that can be used to configure the service once it is deployed.
  • Code package: Each Microservice has a code package that contains the executable and the dependencies that are required by the executable to run.
  • Config Package: You can package the configurations that are required by your Microservice in this folder. A config package is simply a directory in your project which can contain multiple configuration files. Except for Settings.xml file, which is added by default to your reliable service project, the rest of the configurations are not processed by Service Fabric and would need to be processed by the code of your Microservice.

The Settings.xml file can store custom configuration sections and parameters that you can use in your application. For example, you can add a custom configuration section with parameters in your Settings.xml file.

       <Section Name="CustomConfigSection"> 
<Parameter Name="MyParameter" Value="Value1" />
</Section>
You can retrieve this configuration value from your service code.
var configPkg = context.CodePackageActivationContext.
GetConfigurationPackageObject("Config");
var customSection = configPkg.Settings.
Sections["CustomConfigSection"];
var value = customSection.
Parameters["CustomConfigSection"].Value;

Service Fabric allows you to override the configurations based on the environment where the application is hosted as well.

  • Data package: Any static data that is required by your application can be placed inside folders in the PackageRoot directory. Each folder represents one data package and can contain multiple data files. Service Fabric does not process any file that you place inside the folders and the code of your service is responsible for parsing and reading the data.

When you deploy your application from Visual Studio, it creates a package and uses the Deploy-FabricApplication.ps1 script present in the Script folder to deploy your application package to Azure. To deploy your application to Azure, right click on the application project and select the Publish option in the context menu to bring up the publish dialog.

Publish application dialog

In the publish dialog, you can select the relevant application parameter file that you want to get deployed with your application. You can modify the parameters just before deployment by clicking the Edit button. In the dialog box that follows, you can enter or change the parameter's value in the Parameters grid. When you're done, choose the Save button.

You can deploy your application to the selected cluster by clicking on the Publish button.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.26.217