In my previous article, I explained the concepts and theory portion of Azure Service Fabric. In this article, I am going to show you a step by step demonstration of the same.
First of all, on your development machine, you have to install Azure Service Fabric SDK to work with the application. You can download and install Azure Service Fabric SDKs from the link mentioned here.
We are going to use a sample web application provided by Microsoft in Azure samples. You can get that from the link here.
In this Quickstart example, we have a Stateful service based on ASP.NET Core 2.0 template. As mentioned earlier, one should go with a Stateful service when they want to manage the persistent state within the service using reliable collection framework. This one is just for understanding. The actual demo follows.
When you click on OK, it will start creating a service fabric part of the project and will ask us to select ASP.NET Core Web Application templates. As we are creating a backend project which will persist the data that we are going to select, choose ASP.NET Web API template here.
Finally, you can see it will create Service Fabric Application and then the Service Project.
You can know more about the Azure Service Fabric programming model in my previous article - Demystifying Azure Service Fabric.
Now, if you open the .csproj file, you can see it is a standard .NET Core 2.0 based application with Service Fabric reference added to it.
If you look at the main method in Program.cs file, you can see that we do not have any ASP.NET Core 2.0 application specific code. We are actually bootstrapping and then registering the service with service runtime. This is called hosting and activation mechanism in Service Fabric. This process will spin up your service in the Service Fabric Cluster. So, this portion of code defines that these are the service types that are allowed to run in this process.
Now, open the VotingData.cs file which is actually our service class. We can see that our service class implements the stateful service.
Now, let us start the demo.
Go to Azure Portal --> Create a Resource Group --> SFCluster. Once the resource gets created, go to the newly created Resource Group --> SFCluster --> Add New Resource --> Key-Vault.
The reason we are going to add a key-vault here is that we need to use certificates with our Service Fabric Cluster. So, for the fully qualified domain name and the public endpoint we want to communicate with to manage the cluster, there needs to be a certificate there for that, and then we need certificates for internode communication and for secure communication between the cluster nodes as they're communicating to power all these applications.
And you can see that the Key-Vault will be created.
Now, go to Create a Resouce --> Compute --> Service Fabric Cluster.
Provision a new Service Fabric Cluster.
Next, we will set up Cluster Configuration.
For development purposes, we can select a Single Node Cluster. But we are not going to do that. We are going to set the initial VM scale set capacity to 3. The default is 5 and for production use, Microsoft recommends five nodes, but we are going to set this to 3. When you click out of that, you will see that choosing less than five initial VMs is kind of against their production.

Now, on the next screen, they are basically asking you what configuration you want to use for the certificates that are going to be used in the Service Fabric Cluster. Now, we could have this thing attached to a key vault that we created on the fly. The reason we pre-created it is because we wanted to be able to manage it outside of this window.
Basically, we want to pre-create the certificate because it is a little tough to do it after the fact. And what I mean by that initially, we actually defined a name for the cluster. It's going to be your cluster under the domain from Microsoft. But we need to have that name on the certificate if we want to be able to manage the Service Fabric Cluster using the Explorer. And this thing isn't going to actually set that up for us.
So, we are going to set that up manually and I am going to show you the kind of process that I use to make this a little bit easier. So, we are going to leave this here for now.
Next, go to PowerShell. We are going to create our own self-signed certificate for this.
Save and execute the below-mentioned script.
Now, open another tab and open Azure Portal. Go to Resource Group --> SFCluster.

jayanth kulkarniPosted May 23, 2019, 9:05 AM
Super and thanks a lot Krunal!!!!!!