Message splitting in an Orchestration
Introduction
In this blog post, we will try to understand how we can split messages in an orchestration.
Steps
- Let's create a new BizTalk solution and project named 'POCSplitMessages'. Configure the signing key and name the application 'POCSplitMessages'
- Add references to the below dlls
- Microsoft.BizTalk.Pipeline --> get it from (C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.BizTalk.Pipeline\v4.0_3.0.1.0__31bf3856ad364e35\Microsoft.BizTalk.Pipeline.dll)
- Microsoft.XLANGs.Pipeline --> get it from(C:\Program Files (x86)\Microsoft BizTalk Server\Microsoft.XLANGs.Pipeline.dll)
- Create a Racquet Schema in that project. Right Click on the Project --> Add --> New Item --> Schema
- Let us now create an envelope Schema named 'RacquetsEnvelope'. Right Click on the Project --> Add --> New Item --> Schema
- Name the root node 'Racquets'
- Click on Schema node , go to properties and set 'Envelope' to 'Yes'. Go to Imports --> Collections -->
- Add --> Add the 'Racquet' schema
- Click on 'Racquets' node and set Body Xpath to '/*[local-name()='Racquets' and namespace-uri()='http://POCSplitMessages.RacquetsEnvelope']'
- Right-click on the Racquets node and create a child record
- Click on the child record --> properties --> Data Structure type = ns0:Racquet (Reference)
- You can select the Data Structure type from the drop-down.
- Now let's create an orchestration named 'Process'
- Right Click on the orchestration and make it 'Long Running'
- Drop a receive shape of type 'msgRacquetsEnvelope'. Bind it to specify later receive port
- Drag a scope shape below the receive shape and make it long running
- Inside the main scope shape add a child scope and named 'Debatch_Scope' and make it atomic
- Create a variable called 'GetPipelineOutput' of type 'Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages' under Debatch_Scope
- In the Debatch_Scope add an expression shape and add the below line of code
- GetPipelineOutput = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(Microsoft.BizTalk.DefaultPipelines.XMLReceive),msgRacquetsEnvelope);
- This line of code helps to executes the XML receive default pipeline and the msgRacquetsEnvelope is being received in the pipeline.
- This will then split the messages at this stage
- Let's now add a loop shape with the condition given below. It loops through each split message.
GetPipelineOutput.MoveNext()
- Let's now add a message assignment shape with the below lines of code. It should convert the message to 'msgRacquet'. It is basically initializing the variable to null and then getting the current message.
msgRacquet = null;GetPipelineOutput.GetCurrent(msgRacquet);
- Drag and drop a send shape of type 'msgRacquet' and bind it to specify later port
- Add an exception handler by right clicking on the main scope --> New Exception handler
- In the catch exception block drop an expression shape and write the below line of code
- System.Diagnostics.EventLog.WriteEntry("Logs",ex.ToString());
- We are now done with the coding. Let's now build and deploy the solution.
- Configure Bindings
Name of the receive port = POCSplitMessages.ReceiveRacquets.RPName of the receive location= POCSplitMessages.ReceiveRacquets.RLURL = D:\developer\vipin\POCSplitMessages\ReceiveRacquetsPipeline = Pass through receive
Name of the send port = POCSplitMessages.SendRacquet.SPURL: D:\developer\vipin\POCSplitMessages\SendRacquetPipeline = Passthrough send
Testing
- Drop the below message in the receive location file location
<ns0:Racquets xmlns:ns0="http://POCSplitMessages.RacquetsEnvelope">
<ns1:Racquet xmlns:ns1="http://POCSplitMessages.Racquet">
<ID>ID_0</ID>
<Model>Model_0</Model>
<Brand>Brand_0</Brand>
<Price>Price_0</Price>
<Series>Series_0</Series>
<GripSize>GripSize_0</GripSize>
</ns1:Racquet>
<ns1:Racquet xmlns:ns1="http://POCSplitMessages.Racquet">
<ID>ID_1</ID>
<Model>Model_1</Model>
<Brand>Brand_1</Brand>
<Price>Price_1</Price>
<Series>Series_1</Series>
<GripSize>GripSize_1</GripSize>
</ns1:Racquet>
</ns0:Racquets>
- You will see that the above message will be split into 2 and dropped in the send port file location
Message 1
<ns1:Racquet xmlns:ns1="http://POCSplitMessages.Racquet">
<ID>ID_1</ID>
<Model>Model_1</Model>
<Brand>Brand_1</Brand>
<Price>Price_1</Price>
<Series>Series_1</Series>
<GripSize>GripSize_1</GripSize>
</ns1:Racquet>
Message 2
<ns1:Racquet xmlns:ns1="http://POCSplitMessages.Racquet">
<ID>ID_0</ID>
<Model>Model_0</Model>
<Brand>Brand_0</Brand>
<Price>Price_0</Price>
<Series>Series_0</Series>
<GripSize>GripSize_0</GripSize>
</ns1:Racquet>
Code
https://drive.google.com/file/d/1IMRgyMHXYTrVxJdHDzvRUQZfp68CdUtA/view?usp=drive_link
Comments
Post a Comment