Walkthrough: Correlations in BizTalk Orchestration

What is Correlation?

An Orchestration can have more than one instance running simultaneously. Even though each of those multiple instances perform the same action, it does it on different data contained within a message.

Correlation is a process of associating an incoming message with the appropriate instance of an orchestration.

Scenario

Your orchestration is designed to receive a purchase order. It will process the Order and send the order information to Invoicing system. The Orchestration will receive this invoice message and you need to be sure that the invoice message is received by the same orchestration instance that the corresponding purchase order was sent from. 

In this example, the purchase order identification number can be used as a parameter in the correlation set for correlating the purchase order message and Invoice identification number for invoice message.

PurchaseOrderRequest  ->OrderID
Invoice ->InvoiceID

Step by Step

To implement correlation we need to perform below mentioned steps:

  • Promote property required for Correlation. 
  • Create Correlation Type.
  • Create Correlation Set.
  • Use Correlation Set in Receive/Send Shape under property ( Initializing Correlation Sets/ FollowingCorrelation Sets).

To accomplish that we need to:

  1. Create a new BizTalk Project "BizTalkCorrelation".

  2. Add two schemas in the project PurchaseOrderRequest and Invoice based on below image.
     

     PurchaseOrderRequest.xsd

     
     Invoice.xsd  
  3. Add new property schema "MyPropertySchema.xsd" in the project. Rename node Property1 to "CommonID".

  4. Open PurchaseOrderRequest.xsd. Expand order node. Select OrderID. Right click -> promote -> Show promotion -> Select property field tap.

  5. Click folder icon next to Property schemas list. Select Schema -> Select BizTalkCorrelation.MyPropertySchema.

  6. Select OrderID and click Add >>. In property field list select ns0:Commonid from drop down.

  7. Open Invoice.xsd. Expand Invoice node. Select InvoiceID. Right click -> promote -> Show promotion -> Select property field tap.

  8. Click folder icon next to Property schemas list. Select Schema -> Select BizTalkCorrelation.MyPropertySchema.

  9. Select InvoiceIDand click Add >>. In property field list select ns0:Commonid from drop down.

    1. #Step 6 to 9 is important step in our scneario.
  10. Add new orchestration "CorrelationOrchestration.odx" in the project. Design the orchestration as per below picture.

  11. In Orchestration View create Message which is going to be used in this Orchestration.

    1. Identifier -> MessageOrder,  Message Type -> BizTalkCorrelation.PurchaseOrderRequest
    2. Identifier -> MessageInvoice,  Message Type -> BizTalkCorrelation.Invoice  
  12. In Orchestration View create Correlation Type and Correlation set

    1. CorrelationType -> MyCorrelationType (Correlation Properties -> BizTalkCorrelation.CommonID )           
    2. Correlation Set -> MyCorrelation(Correlation Type -> BizTalkCorrelation.MyCorrelationType )        
  13. Configure Orchestration shape as per below description

    1. ReceiveOrder -> Activate (True), Message (MessageOrder)
    2. SendOrder ->Initializing Correlation Set (MyCorrelation), Message (MessageOrder)
    3. ReceiveInvoice -> Following Correlation Sets (MyCorrelation), Message (MessageInvoice)
    4. SendInvoice -> ssage (MessageInvoice)
  14. Configure BizTalk Port and then join it with corresponding Shape.

    1. PortRcvOrder -> PortType (PortTypeRcvOrder, One way, PortDirection(I will be receiving message), PortBinding (Specify Later)
    2. PortRcvInvoice -> PortType (PortTypeRcvInvoice, One way, PortDirection(I will be receiving message), PortBinding (Specify Later)    
    3. PortSndOrder-> PortType (PortTypePortSndOrder, One way, PortDirection(I will be sending message), PortBinding (Specify Later)   
    4. PortSndInvoice-> PortType (PortTypePortSndInvoice, One way, PortDirection(I will be sending message), PortBinding (Specify Later)   
  15. Build and deploy the Solution.

Test the Solution

Configure Receive Port and Send port for above Orchestration And do the testing as per below description

  1. Receive Order message in Orchestration.
  2. Dump Order message to some file location.
  3. Manually create Invoice message and put it in Invoice receive location.
  4. Dump Invoice message to some file location.

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.