Home > BizTalk Server > BizTalk Singleton Orchestration Design

BizTalk Singleton Orchestration Design

Here’s a white paper from Microsoft on creating sequential FIFO orchestrations (this applies to singletons as well), as a follow up to the blog I wrote a few days ago on poorly written singletons. If you read the paper carefully, and pay attention to the “warning” sections, you’ll see that it’s actually very hard to create an orchestration that neatly ends with zero risk of losing messages. This is because a message might come in after the listen shape, but before the orchestration has terminated.

To test this, I created a simple singleton orchestration that adds a deliberate wait of 2 minutes before finishing.

I then deployed the orchestration, and starting sending in messages one by one (by the way, “Do Something” simply writes the one field in the message to the debugger).

So the message with value 1 was sent first, here’s the debugger output:

12880] Field was: 1

Then the message with value 2 was sent in, here’s the output:
[12880] Field was: 2

Then, i waited about 45 seconds, just long enough to get us past the first Delay shape in the orchestration (of 30 seconds).  I submitted a message with value 3, but received no output (as expected).  I waited until the remaining time had finished and saw the orchestration suspend with this error:

The orchestration was not resumable.  I then sent in a message with value 4, here’s the output:
[12880] Field was: 4

So, what does this prove?  If a message comes in before your orchestration has had the time to complete (and you’re no longer waiting to receive a message), you will have unprocessed messages in the orchestration when goes to complete.  I guess the good news is that you can see what that message was by clicking on the message tab, so if you’re willing to run this risk, you might go ahead with this decent, but not perfect, design.

To be absolutely fail-proof, the paper offers a few suggestions, such as stopping the receive location via wmi script as part of the shutdown process.  This is fine and all, except for this one question – how is it supposed to be turned back on? If you do this as part of the same orchestration, you have the same problem you started with!  I guess the one way this could be done would be by adding a “Start Orchestration” shape, which begins with a delay, and then enables the receive location again (the delay is to allow time for the calling orchestration to finish with no risk of losing messages).

Good luck!

Advertisements
Categories: BizTalk Server
  1. June 8, 2008 at 9:14 pm

    Hi Victor,

    Nice post 😉

    This post and the previous post are pointing the things we need to consider by using singleton pattern orchestration, especially if the application expects high traffic of messages.

    Glad to read this one and thanks for the link to the BizTalk white paper which you referred in the previous post.

  2. June 24, 2008 at 11:33 pm

    Good article Richard. I personally, prefer being away from singleton, fifo patterns as much as I can – but sometimes can’t.. An alternate to the singleton process would be redesigning the BizTalk solution in a way to accept your input in periodic intervals. A trigger (file or Db flag) can be maintained to check if the orchestration process is currently running. If yes, terminate the new instance.

    Because the design would implement periodic pulling of data from your buffer (DB/MSMQ, etc), this would ensure that you always have one instance running.

    Food for thought 🙂

    Cheers,
    Zee
    http://zeetalks.wordpress.com

  3. June 25, 2008 at 8:34 am

    Thanks Zee for the comment and for the idea. Your comment touches on another point – often, a true singleton isn’t needed, but some way of preventing too much concurrent processing, something which polling from a queue can take care of pretty well.

  4. JMan
    June 26, 2008 at 6:38 pm

    Hi there

    I am designinig a Biztalk solution at the moment and I am hoping to avoid having 400+ orchestration instances run at once. Please could you read about it on this link and see if a Singleton would help me?

    http://www.biztalkgurus.com/forums/t/10167.aspx

    Thanks
    JMan

  1. June 8, 2008 at 1:30 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: