A microservices architecture consists of a collection of small, autonomous services. Each service is self-contained and should implement a single business capability.
Source:https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices
Azure Service Fabric is a distributed system platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. It allows developers and administrators to avoid complex infrastructure problems and focus on implementing mission-critical, demanding workloads that are scalable, reliable, and manageable.
Prerequisites for creating Microservices in ASP.NET Core,
- Visual Studio 2017 with Azure SDK
- Microsoft Azure Service Fabric SDK
You can download Azure Service Fabric SDK from this URL
To install Azure Service Fabric SDK, you must download Web Platform Installer separately.
After successful installation, you can restart the windows machine. After the system restarts, you will get a message in the system tray as shown below.
You can see the Service Fabric Local Cluster Manager in the system tray. Currently, it supports 1 and 5 node clusters. We can set up a 1 node cluster. Right click the Fabric Local Cluster Manager icon in the system tray and choose “Setup Local Cluster” -> “1 Node”.
It will take a few minutes to set up the local cluster. After some time, you will be notified with a message.
You can click “Manage Local Cluster” to open the cluster. You can get the details about the 1 node cluster.
You can see that 5 different tabs are available. Each tab contains various information about the local cluster.
You can also see the node in the left pane and if you click the node, you will get the details of the node. (Currently, we have only one node available).
We have successfully set up the Service Fabric and local cluster. Now, we can create a microservice application in ASP.NET Core.
Open Visual Studio 2017 in Administrator mode (we need some admin privileges for PowerShell later) and create a new project. Choose “Cloud” -> “Service Fabric Application” template and give a name to our project.
Various types of Service Fabric are available. In this article, we will create a Stateless ASP.NET Core application.
We can also modify the service name. By default, it is Web1.
We can now choose the application type. Currently, I am using .NET Core 2.1 SDK. It will display all the supported templates. We will use MVC template in this article. Click OK button to proceed.
It will take some to create the application and download the library files to our application.
Our application contains two projects. The first project is the Service Fabric project and contains all the parameter files. Most of the files are XML files. In the script folder, one PowerShell script is there. It is used for deploying the application to a local cluster or Azure.
The second project is a pure MVC project. Currently, it contains only one Controller and corresponding Views.
We can build our application and run it. You will be asked to grant permission for the first time.
You may face the following error in execution. You can ignore this error message and proceed.
The system will automatically assign a port to our application and open in a while (I have modified the content in Index.cshtml before running the application).
You can see in the Service Fabric Explorer that our application is listed there.
You can also browse the application details from the left pane.
In this article, we saw how to install Azure Service Fabric SDK and we configured a 1 node cluster locally. After that, we created a Microservice application with MVC Service using Service Fabric and saw how it is running in the cluster.