DEV Community

Tomaž Vinko
Tomaž Vinko

Posted on

CI/CD from Zero To Hero 2/N

This is the second tutorial in CI/CD series. Please refer to first post for introduction.

In this tutorial, we are going to explain what are we CI/CD-ing.
System is hosted on github.

I'm not going into application logic details, because the scope of the tutorial series is to create CI/CD pipeline.
So let's just briefly go through some technical stuff here.

This is Microservice API that receives and validates requests. GET method of TrackingServiceController is pretty much self explanatory:

/// <summary>
/// Validates account and publish event if account is valid
/// </summary>
/// <param name="accountId">Account to validate</param>
/// <param name="data">Published event message data</param>
/// <returns></returns>
public IActionResult Get(int accountId, string data)
    var accountStatusData = new AccountStatusData(accountId);
    // Validates account 

   // Account has passed validation
   if (accountStatusData.HttpCode == HTTP_CODES.SUCCESS_ACCOUNT_ACTIVE)
       if (!_mqttService.Connect())
           accountStatusData.HttpCode = HTTP_CODES.ERROR_MQTT_CONN;
           accountStatusData.HttpMessage = "MQTT Connection error";
           _mqttService.Publish(string.Format("{0}/{1}", _mqttService.RootTopic, accountId),
                         JsonConvert.SerializeObject(new PropagatedData(accountId, data)),
    return new ObjectResult(accountStatusData.HttpMessage) { StatusCode = (int)accountStatusData.HttpCode };
Enter fullscreen mode Exit fullscreen mode
  • WebApi accepts two parameters. The first is the account id that has to be validated and the second is some arbitrary data.
  • Account can have three states: active (exists in DB with active status), non-active (exists in DB but with non-active status), and invalid (does not exist in DB)
  • If the account is valid, then event data is forwarded and published by the MQTT broker on accountId topic

Tracking Service CLI is the command-line client which subscribes to MQTT topics to receive events from TrackingService WebAPI. It can be controlled from the command line. You can see it in action here.

Code unit and integration tests. You can see details here

A particularly interesting method is Performance_Test_500_Requests which tests performance - 500 cycles must be completed in under one second. One cycle represents delivering request through MQTT to subscribing client.

The platform is written in C# and uses SQL Server database. You don't have to have NET Core and SQL Server installed on your local machine because CI/CD pipeline will be executed and compiled by GitHub action.

In the next tutorial, we are going to explain GitHub’s actions. You can fork the repository because you are going to create CI/CD pipeline step by step from scratch.

Top comments (0)