Azure Service Fabric - Building A Stateless Reliable Service - Part Four

Introduction

 
In the first article of this series, we had a brief overview of Microservices architecture and Azure Service Fabric. Then, in the second article, we explored different programming models for Azure Service Fabric. We had a walkthrough of Reliable Services, Reliable Actors, Guest Executables, Containers and ASP.NET Core models for Service Fabric. In the third article, we had a good understanding of a couple of basic concepts in the Azure Service Fabric world like Clusters, Partitions, Replicas, and Instances. Below are links for the previous articles in this series. As a prerequisite, it would be a good idea to go through these articles before proceeding ahead here.
In this article, we will deep dive into building a Stateless Reliable Service using Visual Studio 2019. We will also explore a bit of Service Fabric Local Cluster Manager.
 

Getting things ready

 
Before getting into Visual Studio, Azure Service Fabric needs to be installed from here. Installation steps are pretty simple and are detailed in the installation link. Once the installation completes, the Service Fabric Local Cluster Manager gets installed and this can be seen running in the system tray.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
When we build an Azure Service Fabric application locally, it gets hosted in the Service Fabric Local Cluster Manager. Developers can test it thoroughly for all use cases and then they can move the application to Service Fabric Cluster Manager on Azure. The experience is seamless and is the same whether we are using a local cluster manager or the one on Azure. We will explore more on Cluster Manager on Azure in the next set of articles. However, in this article, we will build the application and host it in the Local Service Fabric Cluster Manager.
 

Creating Azure Service Fabric Stateless Reliable Service Project Using Visual Studio

 
Visual Studio provides templates to build Azure Service Fabric application. Let us open Visual Studio and get started. Open Visual Studio and click on Create a new project. Please note that this demonstration is being done using Visual Studio 2019.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Select Service Fabric Application and click on Next.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Provide a Project name. Click on Create.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Select Stateless ASP.NET Core under .NET Framework. Provide Service Name and click on OK. We will be creating a Web API and hosting it on Azure Service Fabric. That is why we selected the Stateless ASP.NET Core. There are other templates available and can be used as well.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Select API and click on Create. The project gets created.
 
Azure Service Fabric - Building A Stateless Reliable Service
 

Execute the project and inspect it in Service Fabric Local Cluster Manager

 
Now, let us run the project. The Web API project runs and we have output from the values controller that got created when we created the project.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
We will have a detailed code walkthrough in the next article where we will dive into all code essentials. Let us park the code stuff as of now. When we run this project in Visual Studio then below steps are executed.
 
Step 1
 
Code gets compiled.
 
Step 2
 
A PowerShell script which got generated in this project will execute and deploy the Service Fabric Application to the local Service Fabric Cluster.
 
Step 3
 
The values controller gets invoked post deployment to the Cluster.
 
Service Fabric Cluster Manager is important tooling that helps in managing the Service Fabric Cluster. It acts as an orchestrator and takes care of important aspects like service health monitoring, load balancing, application and node management, and other priority aspects.
 
Let us get into the Local Cluster Manager and inspect our deployed API. Double Click on Service Fabric application icon in the System Tray.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
The Cluster Manager will open up in the Web Browser. We can see we have one application hosted on a single node. The service is hosted on a single partition and a single replica. We can see that the application and the node are healthy. This is the same application we built and hosted some time back.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Let us expand the Cluster and the Application. We can see that our application is listed. Click on our application. We can navigate across each of the tabs – Essentials, Details, Deployments, Manifest, and Events and get insights on the application.
 
Azure Service Fabric - Building A Stateless Reliable Service
 
Essentials tab has all the essential information summarized for the Service Fabric. Deployments tab provides information on the nodes where the application is deployed along with the Health Status. Manifest tab highlights the application manifest information.
 
Expanding the Nodes tree will give details on the Node where the application is hosted along with the Instance Information. Here we have hosted it on a single node and we see that listed here.
 
Azure Service Fabric - Building A Stateless Reliable Service

Winding-up

 
In this article, we created a Stateless Service Fabric application. We executed the application and hosted it on the Service Fabric Local Cluster. We had a brief understanding of the Service Fabric Cluster.
 
However, we have not explored the Service Fabric code yet. We will do this in the next article.