BAM API – Using MessagingEventStream to write BAM Events from pipeline components

MessagingEventStream (MES) is used inside a BizTalk pipeline component to write Bam as part of the messaging transactions ensuring that your BAM event persistence remains in sync with the BizTalk pipeline transactions.

Messaging Event Streams are asynchronous and store tracking data first in the BizTalk MessageBox database. Periodically the data is processed and persisted to the BAM Primary Import database by the Tracking Data Decode Service (TDDS). This class is derived from the base class EventStream.

MES is available since BizTalk 2004 with SP1.

Normally, we write the code to produce BAM events in the Execute method of the pipeline component. Execute method have two parameters:

  • An IPipelineContext: contains the pipeline context
  • An IBaseMessage: contains the message being processed.

The pipeline context has a GetEventStream method that returns a MessagingEventStream.

Code sample

public IBaseMessage Execute(IPipelineContext context, IBaseMessage message)
   //Get the Messaging Event Stream
   MessagingEventStream eventStream = context.GetEventStream();

   //Write to BAM
   //Create a new, unique activity identifier to use as the ActivityID in BAM
   string activityId = Guid.NewGuid().ToString() + "_" + DateTime.Now;

   //Start the activity record identified by activityId
   eventStream.BeginActivity("MyTrackingDemo", activityId);

   // Updates the activity record.
   eventStream.UpdateActivity("MyTrackingDemo", activityId, "MESSAGE_ID", message.MessageID, "TRANSACTION_CREATED", DateTime.UtcNow);

   eventStream.EndActivity("MyTrackingDemo", activityId);

   // Optional Flush
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

2 thoughts on “BAM API – Using MessagingEventStream to write BAM Events from pipeline components”

  1. Found what I was looking for. There is only one problem with this code.A could not find reference for MessageEventStream. Instead i used var type. Worked fine for me,

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to Top