How to Develop BizTalk Custom Pipeline Components – Part3

Pipelines contain fixed number of stages and stages contain variable number of components. There are two execution modes of the stages – “All” and “First Match”. In “All” execution mode, all components in the stage are executed one by one in sequence they are placed in pipeline component design. And in “First Match” execution mode, component which recognizes incoming message first takes charge and does processing while rest of the components ignore.

In last two articles, we talked about general and disassemble pipeline components. General pipeline components run in stages (Decode, Validate, Part Resolve, Pre-assemble, encode) with “All” execution mode, and disassemble components run in stage (currently disassemble only) with “First Match” execution mode.

Disassemble components require message recognition capability. Components need to probe message to decide whether message is meant for it or not. Here is how probing algorithm works (referenced from MSDN) –

1. If the stage does not contain any components, the stage is not run and the message is given to the subsequent stages for processing.

2. If the stage contains component(s), check if the component implements the probinginterface. If not, the Messaging Engine invokes the component. The stage processing is done and the message is given to the next stage.

3. If probing interface is implemented then component executes probing on message. If probe returns affirmative response (return value = True) , the component is run. Then the stage processing is done and the message is given to a next stage.

4. The Messaging Engine gets the next component in the stage. If there are no more components and none of the components have been run, it generates an error that pipeline processing has failed. If there are no more components and at least one component has been run, the processing is done.

Probing enabled components are developed for this purpose. Let’s see details about it.

Developing Probing Enable Component

Probing component does not have identity in itself. Other pipeline components need to implement IProbeMessage to add probing capability in them. Probing enable component can investigate incoming message (check schema, namespace, body content etc) to identify message.

IProbeMessage Interface

Members

Usage

Probe

Method. Method is implemented to investigate message to decide if message is recognizable or not. If message is recognizable then it returns “True” otherwise “False”.

You can check message schema, namespace, body content or some other mean to recognize message.

Code Sample

I am implementing probing interface in a disassemble component. And as part of probing logic, I am checking namespace of incoming message (just to keep things simple). Well, in real implementation, use of probing interface makes more sense if multiple disassemble component are deployed in single disassemble stage. Because then you can have separate message recognition logic in separate components so that correct component can pick appropriate message.

1. Create a disassemble pipeline component by implementing all required interfaces. For quick reference, please refer my previous article – https://blogs.msdn.com/brajens/archive/2006/12/03/how-to-develop-biztalk-custom-pipeline-components-part2.aspx

2. Implement on more interface IProbeMessage.

3. Add implantation for IProbeMessage interface.

public bool Probe(IPipelineContext pContext, IBaseMessage pInMsg)

{

       bool probeResult = false;

       string originalDataString;

       try

          {

              //fetch original message

              Stream originalMessageStream = pInMsg.BodyPart.GetOriginalDataStream();

              byte[] bufferOriginalMessage = new byte[originalMessageStream.Length];

              originalMessageStream.Read(bufferOriginalMessage, 0, Convert.ToInt32(originalMessageStream.Length));

  originalDataString = System.Text.ASCIIEncoding.ASCII.GetString(bufferOriginalMessage);

              XmlDocument originalMessageDoc = new XmlDocument();

               

              //load original message

              originalMessageDoc.LoadXml(originalDataString);

              //fetch namespace and root element

              string namespaceURI = originalMessageDoc.DocumentElement.NamespaceURI;

              if (namespaceURI.Equals("https://somenamespace"))

                  probeResult = false;

              else

                  probeResult = true;

              return probeResult;

 

          }

        catch (Exception ex)

          {

              throw new ApplicationException("Error in probing message: " + ex.Message);

          }

}

4. You can also define pipeline design time property and read namespace value (“https://somenamespace”) from there.

5. With this, component now have message recognition capability. Build the project and it is ready for use.

Deploy Component and Use

To deploy pipeline component, Copy component dll to “C:\Program Files\Microsoft BizTalk Server 2006\Pipeline Components”.

Pipeline component is now ready to use. In BTS receive pipeline project, add this pipeline component dll in toolbar and then use in disassemble stage.

Summary

When multiple custom disassemble components are used in disassemble stage then probing capability becomes a very critical functionality because appropriate component should pick incoming message for processing. Probing interface does wonders in such cases. Hope this article was useful. Please ping me if you have any query/suggestion.

Next article will be last in this series. Thanks.