다음을 통해 공유


Debatching Technique in BizTalk Development

Hi All,

I had to process a few Sql stored procedure results that have large number of records in my project recently.  Every record could have its different logic so I  had to  get them one by one  and to process in different business logic.

For this purpose,  I will try to describe simply how to use debatching technique in BizTalk solutions in this article. I will not draw out details. I suppose that you are already familiar  to BizTalk development process.

In some cases you can want to extract special sub messages from a main message structure and to process them in separate business logic. For example, in simple manner you can face such a scenario  that each record will be processed in different logic and they will have different features. 

It can be in Sql stored procedure results, WCF responses or flat files also. Its not important where is it.  In such  cases we can do some actions about it.  We have to extract sub messages from main message and to construct this sub message. Its called debatching in BizTalk. To achive this task we should do some sub tasks also

• To calculate record count to able to make a loop 
• To extract sub messages from main messages with Xpath queires
• To process this sub single message
• To terminate debatching message loop

As you can see in  following code snippet, you can calculate the total record count in a message and use it in Loop Shape in orchestration.
After that by using an expression shape  you can extract sub message from main message. Here, loopCount is local variable that holds current iteration in message navigation,  msgAppEntityStatusListRessingle represents a message for a Xml Schema(You have to add a schema to solution for  to be extracted message). 

Get Record Count

recordCount = System.Convert.ToInt32(xpath(msgAppEntityStatusListRes,"count(/*[local-name()='AppEntityStatusListResponse' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0'
 and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/dbo/AppEntityStatusList'])"));

Construct Sub Message

Tcb.OcpHelper.OcpHelper.WriteDiagnosticLog("Constructing message msgAppEntityStatusListResSingle ... " + loopCount.ToString() );
Tcb.OcpHelper.OcpHelper.WriteEventLog("Constructing message msgAppEntityStatusListResSingle ..." + loopCount.ToString(),System.Diagnostics.EventLogEntryType.Information);
xPathStatement = System.String.Format("/*[local-name()='AppEntityStatusListResponse' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0'
 and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/dbo/AppEntityStatusList'][{0}]", loopCount);
Tcb.OcpHelper.OcpHelper.WriteDiagnosticLog("XPath Statement for msgAppEntityStatusListResSingle : AppEntityStatusListResponse [" + loopCount.ToString() + "]  " + xPathStatement);


msgAppEntityStatusListResSingle = xpath(msgAppEntityStatusListRes, xPathStatement);
Tcb.OcpHelper.OcpHelper.WriteDiagnosticLog("Constructing message msgAppEntityStatusListResSingle SUCCEED...");
Tcb.OcpHelper.OcpHelper.WriteEventLog("Constructing message msgAppEntityStatusListResSingle SUCCEED...",
    System.Diagnostics.EventLogEntryType.Information);
Company.OcpHelper.OcpHelper.WriteDiagnosticLog("Getting ActionType of msgAppEntityStatusListResSingle ... " );
Company.OcpHelper.OcpHelper.WriteEventLog("Getting ActionType of msgAppEntityStatusListResSingle ... " ,
    System.Diagnostics.EventLogEntryType.Information);

After that you can free to process the sub messages. I put a image of the full orchestration here to make an opinion.  It looks large but as i explained important points is to get sub message in this approach.

For this purpose,
For this purpose,

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.