A very powerful feature of BizTalk is Message Tracking. You can use the BizTalk Server Administration Console to enable message body and message property tracking. There you can also view the tracked message body and all the promoted properties for the message. There is only one but, Tracking a lot of data can be bad for the performance so Microsoft recommends that you should only enable the minimum tracking required for your application, as this will reduce the amount of data logged and lower the risk of tracking bottlenecks.
The BizTalk Performance Optimization Guide says the following about message body tracking:
Only use message body tracking if necessary. Depending on message throughput and message size, message body tracking can cause significant overhead. While BizTalk activity tracking has obvious benefits for debugging and auditing, it also has considerable performance and scalability implications. Therefore, you should track only data that is strictly necessary for debugging and security reasons, and avoids tracking redundant information.
So, it can be useful in a development- or test environment but you can't use this feature in a production environment! But also in a Production environment you want to be able to track message bodies.
MongoDB could be a very good alternative to track message bodies because MongoDB is a web scale database, and doesn't use SQL or JOINs, so it's high-performance. An other advantage is that it is a document database. You can store the entire BizTalk message as a document in a collection but you can still search on specific items in the document.
MongoDB can be installed on many platforms such as Windows Azure but in this example I’m going to install it on the local machine.
In the steps below I’m going to create an Itinerary Messaging Service that you can use inside an ESB to track message bodies. Notice that you can also use the code in a “regular” Orchestration or Pipeline Component!
// This class serves as the root object for working with a MongoDB server.
MongoClient client = new MongoClient(connectionString);
var server = client.GetServer();
var mongoDbDatabase = server.GetDatabase(database);
var mongoDbCollection = mongoDbDatabase.GetCollection(collection);
// Parste the json to a BsonDocument (a collection of name/value pairs)
BsonDocument document = BsonDocument.Parse(jsonText);
// Insert the document in the collection
WriteConcernResult insertResult = mongoDbCollection.Insert(document);
ok = insertResult.Ok;
<itineraryService id="1030" name="TrackingService" type="itHero.ESB.Services.TrackingService, itHero.ESB.Services, Version=126.96.36.199, Culture=neutral, PublicKeyToken=7f76ec21959e67b4" scope="Messaging" stage="All"/>
Once the itinerary is deployed to the Itinerary Store database and the Tracking Service is placed in the GAC, the solution is ready to be tested.
Create a Receive Port and a Receive Location with the BizTalk Administration Console and drop a message in it.
I’ve used the Trace class in System.Diagnostics to trace the steps but you can also use another component for it like ETW tracing.
The Tracking Service example showed that MongoDB is a really good alternative for tracking message bodies. I've always been a big fan of SQL Server so I was a bit skeptical about MongoDB but seeing is believing! It really is much faster than SQL Server and you can still search on individual items in a message.
You can download the sample Messaging Service with the source code here: