Setting unique Tracking Id in BizTalk Logic Apps send port

Setting unique Tracking Id in BizTalk Logic Apps send port

Published on : Jun 23, 2017

Category : BizTalk Server

srini

Author

I was working on a POC which involved sending a message from BizTalk send port to a logic app with message’s HTTP header enriched to have a unique tracking id.  Achieving this was not straight forward. In this article, I will explain the issue I faced and resolution.
You can download the entire article as a PDF document. Setting unique Tracking Id in BizTalk Logic Apps send port

Problem explained

I have a simple logic app with an HTTP request trigger and dumps the received message into a Google drive folder. Setting unique Tracking Id in BizTalk Logic Apps send port My BizTalk application has an FTP receive port and a send port configured to use Logic Apps adapter. send port subscribes to messages from FTP receive port and sends them out to a logic app.  Setting unique Tracking Id in BizTalk Logic Apps send port As we are aware logic apps provide an option to send a client tracking id in the form of a custom HTTP header x-ms-client-tracking-id. Refer the article  https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-monitor-your-logic-apps to know more about monitoring and tracking in Logic apps. The static logic app sends adapter provides an option to configure the custom HTTP headers in the port configuration as shown below. Setting unique Tracking Id in BizTalk Logic Apps send port Since I want to send a unique tracking id per message, I cannot set a static value in port configuration. Hence I did what any other BizTalk developer would do. tried to look for a property schema specific to Logic Apps adapter. However, I could not find one in the list of property schemas deployed in my BizTalk environment. This put me in a situation where I don’t have the option to send unique tracking id per message.

Solution

I started to contemplate on how a dynamic send port would send messages to logic apps without any property schema related to logic app adapter is deployed.  With a little bit of research, I came to know that the Logic Apps adapter internally leverages WCF Web Http binding. This directed me toward WCF property schema. So I wrote a  HttpHeaders context property in a custom pipeline component in send port.

inMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", "x-ms-client-tracking-id: " + trackingId);

You can download the entire article as a PDF document. Setting unique Tracking Id in BizTalk Logic Apps send port
This made the trick! Now I am able to view the tracking id in my logic apps run history. Setting unique Tracking Id in BizTalk Logic Apps send port However, when I send another message, I saw that google drive connector was failing due to duplicate file name.  I used the tracking Id as the file name. This means somehow tracking id which I have set is same for subsequent runs.  This was again a setback for me as I was still not able to receive unique tracking id per message. Setting unique Tracking Id in BizTalk Logic Apps send port Again with a little bit of research, I understood that this is the normal behavior for a static WCF send port to cache the headers set using context properties. The option was to create a dynamic port. Since I do not want to create a dynamic port, I just tried to set a context property related to dynamic ports. So I added an additional line to my code in pipeline component.
inMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", "x-ms-client-tracking-id: " + trackingId);

inMsg.Context.Write("IsDynamicSend", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);

This solved the issue! I am now able to send a unique tracking id per message using Logic Apps adapter in BizTalk static send port.

Summary

In summary, we need to remember following points
  • Logic app provides an option to send client tracking id using a custom HTTP header “x-ms-client-tracking-id”
  • Logic Apps send adapter leverages WCF web HTTP binding behind the scene.
  • If you want a static Logic Apps port to send the tracking id per message then you need to promote two properties HttpHeader and IsDynamicSend
You can download the entire article as a PDF document. Setting unique Tracking Id in BizTalk Logic Apps send port