Try for free Book a demo

Announcing dotnet library for Turbo360 BAM

Turbo360

6 Mins Read | Last modified on February 15th, 2024

Announcing dotnet library for Serverless360 BAM

Introduction

We have recently announced the Turbo360 BAM feature which supports end-to-end distributed tracing at our flagship event INTEGRATE 2019. Which garnered a lot of interests from our customers. Along with the feature we also shipped custom connectors for services like Logic Apps, Microsoft Flow and Power Apps.

However, some of our customers wanted the ability to directly use our API’s instead of connectors so that it is possible to log activities from any kind of application like APIs, Azure Functions, Windows Service, etc. As a customer-centric company, we listened to our customers and here we are launching the Nuget Package library which will help you to directly log business activities from your .Net applications.

Nuget Library

Ship Any Where Logistics Scenario

Let us look at an example business process from the logistics domain. This example is a simplified version of the actual system but you can see that multiple types of messages flowing through different systems. 

dotnet library

What is Business Process

Business Process – A collection of related transactions that serve a business goal for the customer(s). For example, ShipAnyWhere Logistics is a business process that encompasses multiple transactions.

Business Transaction – A collection of related stages or milestones that achieve a specific activity. For example, Booking Request, Booking Confirmation, Shipping Instructions, Invoice and Milestone Status

Stage – A milestone within a business transaction that performs a well-defined task. For example, Receiving an order from a customer, Transforming it to a format that the supplier expects and sending the order to the supplier system, are few milestones in the booking transaction.

Properties – A value in the business transaction which is of specific importance in the context of the transaction. For example, BookingId, Price could be a couple of data values that business might be interested in to track in the order stages, They can be searched for if the property is a global property.

The above business process can be represented in the Turbo360 BAM portal as below.

dotnet library

In Turbo360 BAM the logging is happening at a stage level.  Below is the list of operations that can be performed on each stage.

  • Start Activity – Starts a business stage activity
  • Update Activity – Updates an existing stage activity
  • Archive Activity – Archives the message and message context of a message
  • Log Exception Activity – Log if there are any exceptions

Let’s Look at Some Code

For the logistics operation let’s assume we are using Azure Functions as our integration service. For the business transaction Booking Request the code may look something like below.

public static class LogisticsProcessing
{
	[FunctionName("BookingRequest")]
	public static async Task<IActionResult> Run(
			[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
			ILogger log)
	{
		log.LogInformation("C# HTTP trigger function processed a request.");

		//Receive
		return new OkObjectResult("Some response");
	}


	static async void Process(IActivityService service,Guid mainActivityId)
	{
		/**
		 * Do some business processing like post message to a queue
		 * or calling db etc
		 * 
		 */			
	}

	static async void Send(IActivityService service,Guid mainActivityId)
	{
		/**
		 * Send message to some carrier based in the message
		 * 
		 */
	}
}

So the azure function basically receives an HTTP Request and its does business processing and sends the message to some carrier. Lets say we want to track these activities

First, include the Kovai.Turbo360.Bam nuget package in your Azure Function.

Nuget library package

After that, you would have to procure the Turbo360 access key from the access keys page of the portal.

dotnet library

[FunctionName("BookingRequest")]
public static async Task<IActionResult> Run(
		[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
		ILogger log)
{
	log.LogInformation("C# HTTP trigger function processed a request.");

	IActivityService service = new ActivityService("V9sOiZ6eE0jDjq25zFpKEzejlk2jAija4cCqU290b15qcoi8/iynvw==");
	var response = await service.StartActivity(new StartActivityRequest()
	{
		BusinessProcess = "Ship Any Where Logistics",
		BusinessTransaction = "Booking Request",
		CurrentStage = "Receive"
	});

	await service.UpdateActivity(new UpdateActivityRequest()
	{
		BusinessProcess = "Ship Any Where Logistics",
		BusinessTransaction ="Booking Request",
		CurrentStage = "Receive",
		MainActivityId = response.MainActivityId,
		StageActivityId = response.StageActivityId,
		Status = StageStatus.Success
	});
	return new OkObjectResult(response);
}

In the above code, we are starting and completing the receive stage of the booking request business process. Similar for the next two stage the code would look like

public static class Logistics
{
	[FunctionName("BookingRequest")]
	public static async Task<IActionResult> Run(
			[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
			ILogger log)
	{
		log.LogInformation("C# HTTP trigger function processed a request.");

		IActivityService service = new ActivityService("V9sOiZ6eE0jDjq25zFpKEzejlk2jAija4cCqU290b15qcoi8/iynvw==");
		var response = await service.StartActivity(new StartActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction = "Booking Request",
			CurrentStage = "Receive"
		});

		await service.UpdateActivity(new UpdateActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction ="Booking Request",
			CurrentStage = "Receive",
			MainActivityId = response.MainActivityId,
			StageActivityId = response.StageActivityId,
			Status = StageStatus.Success
		});
		return new OkObjectResult(response);
	}


	static async void Process(IActivityService service,Guid mainActivityId)
	{
		var stageName = "Process";

		var response = await service.StartActivity(new StartActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction = "Booking Request",
			CurrentStage = stageName,
			PreviousStage = "Receive",
			MainActivityId = mainActivityId
		});

		/**
		 * Do some business processing like post message to a queue
		 * or calling db etc
		 * 
		 */

		await service.UpdateActivity(new UpdateActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction ="Booking Request",
			CurrentStage = stageName,
			MainActivityId = response.MainActivityId,
			StageActivityId = response.StageActivityId,
			Status = StageStatus.Success
		});
		
	}

	static async void Send(IActivityService service,Guid mainActivityId)
	{
		var stageName = "Send";

		var response = await service.StartActivity(new StartActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction = "Booking Request",
			CurrentStage = stageName,
			PreviousStage = "Process",
			MainActivityId = mainActivityId
		});

		/**
		 * Send message to some carrier based in the message
		 * 
		 */

		await service.UpdateActivity(new UpdateActivityRequest()
		{
			BusinessProcess = "Ship Any Where Logistics",
			BusinessTransaction ="Booking Request",
			CurrentStage = stageName,
			MainActivityId = response.MainActivityId,
			StageActivityId = response.StageActivityId,
			Status = StageStatus.Success
		});
	}
}

Now if you are processing message in this azure function you should see the tracked activities like below.

Tracked activities in Turbo360

As you can see its pretty straightforward process to use this library in your projects. So if you are a business and in need of tracking your business activities from various components in your organization you can make use of the library. We also open sourced our library in Github. So if you are facing any issues with the library or if you want to contribute to the library you can do that.

Conclusion

I hope this blog post provided a better understanding on the library and its intention. We also have a more detailed documentation. Please check out that as well.

This article was originally published on Jun 18, 2019. It was most recently updated on Feb 15, 2024.

Related Articles