I ran into a slightly unusual requirement this week, and thought I’d do a post about it in case someone else needs this pattern.
We needed to include, in a file that was being transmitted to a trading partner, a “file sequence number” that would be used for potential auditing/troubleshooting. This number (which is included inside the file itself) would start at “1”, and would increment every time we sent one of these files throughout the day. It would reset to “1” every day.
So, constraints were:
· Number must be persisted so we can “remember” the last sequence number used, even though the process itself is completely stateless
· The solution runs in a farm, so the persistence mechanism used needs to be shared
· The file was being created by a map, so we can’t do something like a singleton orchestration that terminates itself every day (in addition, this would not be reliable as someone could terminate the orchestration and the number would reset).
The solution I implemented was based on using BizTalk’s cross referencing API.
· I added a “GetSequenceNumber” method to a helper class
· The GetSequenceNumber method uses the Microsoft.BizTalk.CrossReferencing APIs to access the shared data store (tables in the BizTalkMgmt database)
· The GetSequenceNumber method includes the “has the day changed since last time I got a number?” logic. It updates the shared “last date” and “sequence number”
· I added a scripting functoid to the map, it uses the helper class’s assembly, and calls the GetSequenceNumber method
· I made this a generic function by passing in a couple of parameters that specify application and application instance values for the CrossReferencing DLLs, thereby potentially re-using this sequence logic elsewhere by just having different parameters in the scripting functoid
· In order to use the APIs, you need to go through an import process first to create the database entries (the data is stored in the BizTalkMgmtDb database, in the xref_* tables). There’s a command line tool that facilitates this, I scripted the call to that and added it to our deployment scripts
Works like a charm, and it was a simple thing to do.
Of course the APIs are documented, but a lot of people don’t seem to know about them J
Some supplemental reading on the topic by my co-worker Tom Canter and fellow-MVP Eric Stott can be found at:
http://blogs.neudesic.com/blogs/enterprise_integration/archive/2007/02/13/4244.aspx
http://blog.biztalk-info.com/archive/2007/02/14/BizTalk_Cross_Referencing_Funcionality.aspx