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
- {
- // GET api/values
- [HttpGet]
- public ActionResult<string> Get()
- {
- return "This is version 1.";
- }
- // GET api/values/5
- [HttpGet("{id}")]
- public ActionResult<string> Get(int id)
- {
- return "value";
- }
- // POST api/values
- [HttpPost]
- public void Post([FromBody] string value)
- {
- }
- // PUT api/values/5
- [HttpPut("{id}")]
- public void Put(int id, [FromBody] string value)
- {
- }
- // DELETE api/values/5
- [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
- {
- // GET api/values
- [HttpGet]
- public ActionResult<string> Get()
- {
- return "This is version 2.";
- }
- // GET api/values/5
- [HttpGet( "{id}" )]
- public ActionResult<string> Get( int id )
- {
- return "value";
- }
- // POST api/values
- [HttpPost]
- public void Post( [FromBody] string value )
- {
- }
- // PUT api/values/5
- [HttpPut( "{id}" )]
- public void Put( int id, [FromBody] string value )
- {
- }
- // DELETE api/values/5
- [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/

MichaelPosted Jul 28, 2019, 6:43 PM
Party cluster free trial has been discontinued.... https://blogs.msdn.microsoft.com/azureservicefabric/2019/02/05/discontinuing-party-clusters/
Sarathlal SaseendranPosted Jan 2, 2019, 8:26 AM
Very well explained Thiago Vivas. Keep it up