Geeks With Blogs

News This is the *old* blog. The new one is at

Elton Stoneman
This is the *old* blog. The new one is at


We had an interesting problem which looked at first like a Parallel Convoy situation – the source was sending message segments which we needed to build up into a whole message and send on to the target. The source segments would be arriving in any order, and the sequence wasn't important – each would contain just one part of the whole message.

Initially we knew the number of segments per message, so a straightforward Parallel Convoy was the obvious approach. But in this case there were two markers to signify the completion of the convoy: the segment count and the fact of having a whole message ready to send, so I opted for a more dynamic design.

The work is all done in an orchestration with an activating receive that initiates the correlation set. It then creates the outgoing message and populates whichever part is available from the first segment. If the outgoing message is incomplete, the orchestration enters a loop, starting with a receive following the correlation set.

Within the loop similar logic takes place after the receive – the outgoing message is updated from whichever part is available in the next incoming segment and is validated for completeness. If not complete, the loop continues. When the outgoing message is fully populated, the loop exits and the message is sent:

Fairly straightforward, the key point is populating the interim message. You don't want to construct an actual message as it'll make its way to the MessageBox and get suspended. My approach was to use a variable of a serializable class which matched the outgoing schema, instantiate it from the activating receive and update it in the expressions:

if (!System.String.IsNullOrEmpty(IncomingSegment(x.y.Schemas.PropertySchema.CustomerId)))

{OutgoingMessage.CustomerId = IncomingSegment(x.y.Schemas.PropertySchema.CustomerId);}


(Note this uses a last-man-wins approach if two segments in the same set have the same property populated).

The code for validating the completed message can then be isolated in the .Net class, allowing for clean unit testing and a simple logical expression for the loop:


This design has the advantage that the number of segments is irrelevant and the process will function if the source changes from five segments per message to ten or one – and even copes with different segment counts between sets. It relies on being able to validate that input is complete based on message content, but allows that logic to be neatly encapsulated.

Posted on Monday, September 15, 2008 7:31 PM BizTalk 2006 R2 | Back to top

Comments on this post: Dynamic Looping Convoys

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Elton Stoneman | Powered by: