In this article, we will be creating a sample MicroService project using Visual Studio and Service Fabric. Then, we will publish that on Azure by applying continuous integration and continuous deployment to this sample project using Azure Pipelines.
Related Articles
What is Service Fabric?
"Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. Service Fabric also addresses the significant challenges in developing and managing cloud-native applications. Developers and administrators can avoid complex infrastructure problems and focus on implementing mission-critical, demanding workloads that are scalable, reliable, and manageable. Service Fabric represents the next-generation platform for building and managing these enterprise-class, tier-1, cloud-scale applications running in containers." Read more here >>
Creating a sample project
Setting up the environment
Create the project of type Service Fabric named ServiceFabricSample.
Create the service of type .NET Core Stateless Service named StatelessServiceSample.
Choose the API template.
The result of your newly-created MicroService project.
Push F5 and see the result of your service.
Check your cluster status.
- Open your local cluster, right-click on your Service Fabric icon in the Icons Task Bar.
- Navigate through your apps and settings.
Update the default controller to change the returning message.
- namespace StatelessServiceSample.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class ValuesController : ControllerBase
- {
-
- [HttpGet]
- public ActionResult<string> Get()
- {
- return "This is version 1.";
- }
-
-
- [HttpGet("{id}")]
- public ActionResult<string> Get(int id)
- {
- return "value";
- }
-
-
- [HttpPost]
- public void Post([FromBody] string value)
- {
- }
-
-
- [HttpPut("{id}")]
- public void Put(int id, [FromBody] string value)
- {
- }
-
-
- [HttpDelete("{id}")]
- public void Delete(int id)
- {
- }
- }
- }
Publishing your MicroService to Azure using Party Clusters
Read more about party clusters
here.
Register and get your cluster information.
Configure your Visual Studio with Party Cluster info
Read more about connecting to party cluster
here.
Validate the published result
Publishing your MicroService to Azure using Azure Service Fabric Clusters
A pre-created Service Fabric Cluster will be used here.
Set the publish profile in Visual Studio.
Check the published result.
Implementing CI to our sample project
Read more about implementing CI
here.
Create a new Build Pipeline.
Point it to your repository.
Select Service Fabric template.
Your tasks will be generated according to the selected template, usually, we do not need to change anything here. Now, let's queue our build.
Validate your build result.
Implementing CD to our sample project
Read more about implementing CD
here.
Create a new release pipeline.
Select the Service Fabric template.
Configure your release pipeline.
Set up your cluster endpoint.
Turn on the trigger.
Testing the whole process
Update the ValuesController.
- namespace StatelessServiceSample.Controllers
- {
- [Route( "api/[controller]" )]
- [ApiController]
- public class ValuesController : ControllerBase
- {
-
- [HttpGet]
- public ActionResult<string> Get()
- {
- return "This is version 2.";
- }
-
-
- [HttpGet( "{id}" )]
- public ActionResult<string> Get( int id )
- {
- return "value";
- }
-
-
- [HttpPost]
- public void Post( [FromBody] string value )
- {
- }
-
-
- [HttpPut( "{id}" )]
- public void Put( int id, [FromBody] string value )
- {
- }
-
-
- [HttpDelete( "{id}" )]
- public void Delete( int id )
- {
- }
- }
- }
Commit your changes.
Check your build pipeline, you must have a new build.
Check your release pipeline, you must have a new deployment.
Check your Cluster Manager to see the diferent version.
Congratulations, you have successfully created your Service Fabric MicroService and deployed it.
- Project on Azure Repos here.
References
https://azure.microsoft.com/en-us/services/service-fabric/