Unleashing the spool table (well at least partly)


Today was one of those days that I couldn’t resist my need to find out what happens under the BizTalk covers. I think every BizTalk developer recognizes this.

In particular I wanted to examine the context properties of message stored in the spool table. The reason I wanted to do this is a little bit irrelevant for now and might eventually come back in a future post or article.

Anyway, the spool table has a very simple structure:

CREATE TABLE [dbo].[Spool](
    [uidMessageID ] [uniqueidentifier] NOT NULL,
    [UserName] [sysname] NOT NULL,
    [PublishingServer] [sysname] NOT NULL,
    [OriginatorSID] [sysname] NOT NULL,
    [OriginatorPID] [nvarchar](256) NOT NULL,
    [dtTimeStamp] [datetime] NOT NULL,
    [dtExpiration] [datetime] NULL,
    [nvcMessageType] [nvarchar](128) NULL,
    [nNumParts] [int] NOT NULL,
    [uidBodyPartID] [uniqueidentifier] NULL,
    [nvcBodyPartName] [nvarchar](256) NULL,
    [nCounter] [int] NOT NULL,
    [imgContext] [image] NULL )

The column I was interested in is called ‘imgContext’. For each message this column stores an encoded serialized value of the collection of context properties, something like this:

0xC4E0906C1849D311A24200C04F60A5330500000074000000680074007 etc, etc….

For my experiment I wanted to work in code with IBaseMessageContext interface much like the way we do when coding custom pipeline components.

So the question was how can I directly create a IBaseMessageContext instance from ‘0xC4E0906C1849D311A……’?

After clicking around for quite a while in Reflector I was able to create a very simple console application that gave me access to the context of the message. The only thing I needed to provide was the Message ID which can be fetched from the column ‘uidMessageID’ or the BizTalk Administration Console. Here is the code:

image

Running writes the context properties to the console:

image

I hope this code will help someone who, like me, also has the need to go beyond the BizTalk borders :-)

A couple of notes:

  • This code is only for ‘research’ purposes and should never be used in production environments or any other purpose.
  • If you want to do this. Make sure the message stays in the spool table. If the message is processed by BizTalk and everything went fine the message will be deleted from the spool table. To prevent this you can set a breakpoint on the processing orchestration, create an error or disable the BizTalk Sql agent jobs.
  • The code was developed using BizTalk 2009 but should also work in previous versions.

6 Responses to “Unleashing the spool table (well at least partly)”

  1. BizTalk: Load context properties from the Spool table imgContext value « Zeeshan’s Integration Bits Says:

    [...] May 14, 2009 by Zeeshan Refer: http://biztalkmessages.vansplunteren.net/2009/05/13/unleashing-the-spool-table-well-at-least-partly/ [...]

  2. Zeeshan Says:

    Thats quite interesting!. When the spool table loads up and “nothing” appears to be working – the spool table could be looking “into” and the source of those messages could be identified this way :) ..

    Great stuff :)

  3. Thiago Almeida Says:

    Cool post Randal, thanks for sharing! I’ve been meaning to post on that as well ever since Alister posted a similar code to the comments on one of my blog posts (http://connectedthoughts.wordpress.com/2008/04/02/3-ways-of-programatically-extracting-a-message-body-from-the-biztalk-tracking-database/).
    We were looking at the tracked message data in the DTA database, but getting the context out is pretty much the same.

    • Randal van Splunteren Says:

      Hi Thiago, thanks for your comment. I always try to find out if a certain topic hasn’t been already described somewhere before I blog. While googling I did find your blogpost on tracking . Seems like I always end up in your blog when I’m searching BizTalk stuff anyway :-) . I failed to see the Allistars comment though. Thanks!

  4. Ajeet Kumar Says:

    Nice post Randal!!!!!!! I have one question..consider a scenario where I have one flat file ..which I disassemble and promote any property(custom property) by extending the default FlatFile disassembler. Here I have few confusion:

    Say I have 4 messages after disassembling, and promoted property should have 4 different values for each message. I have confusion, for promoted property what BizTalk stores in the context(before saving to Db), its value or reference to the Property.

    • Randal van Splunteren Says:

      Hi Ajeet,

      Thanks for your comment. If I understand your question correctly I would say the value is stored in the context.

Leave a Reply