BizTalk Server: Partner Direct Ports and the Orchestration Chains
Partner Direct Port is one of the BizTalk hidden gems. It opens simple ways to the several messaging patterns.
This article based on the Kevin Lam’s blog article. The article is pretty detailed but it still leaves several unclear pieces. So I have created a sample and will show how it works from different perspectives. (The original article was on my blog. The source code is it the MSDN Gallery.)
Requirements
Let's imagine these requirements:
- We should create an orchestration chain where the messages should be routed from the first stage to the second stage.
- The messages should not be modified.
- All messages has the same message type.
Common artifacts
It is interesting but all orchestrations use only one port type.
http://code.msdn.microsoft.com/site/view/file/72395/1/Schema1PortType.JPG
It is possible because all ports are one-way ports and use only one operation.
I have added a B orchestration. It helps to test the sample, showing all test messages in channel.
http://code.msdn.microsoft.com/site/view/file/72396/1/Orch.B.JPG
The Receive shape Filter is empty. A Receive Port (R_Shema1Direct) is a plain Direct Port. As you can see, a subscription expression of this direct port has only one part, the MessageType for our test schema: A Filer is empty but, as you know, a link from the Receive shape to the Port creates this MessageType expression.
http://code.msdn.microsoft.com/site/view/file/72397/1/B.Subscription.JPG
I use only one Physical Receive File port to send a message to all processes.
Each orchestration outputs a:
Trace.WriteLine(“<Orchestration Name>”)
Forward Binding
This sample has three orchestrations: A_1, A_21 and A_22.
A_1 is a sender, A_21 and A_22 are receivers.
Here is a subscription of the A_1 orchestration:
http://code.msdn.microsoft.com/site/view/file/72398/1/A_1.Subscription.JPG
It has two parts
- AMessageType. The same was for the B orchestration.
- A ReceivePortID. There was no such parameter for the B orchestration. It was created because I have bound the orchestration port with Physical Receive File port. This binding means the PortID parameter is added to the subscription.
http://code.msdn.microsoft.com/site/view/file/72399/1/All.jpg
How to set up the ports?
- All ports involved in the message exchange should be the same port type. It forces us to use the same operation and the same message type for the bound ports.
- This step as absolutely contra-intuitive. We have to choose a Partner Orchestration parameter for the sending orchestration, A_1. The first strange thing is it is not a partner orchestration we have to choose but an orchestration port. But the most strange thing is we have to choose exactly this orchestration and exactly this port.It is not a port from the partner, receive orchestrations, A_21 or A_22, but it is **A_1 **orchestration and S_SentFromA_1 port.
- Now we have to choose a Partner Orchestration parameter for the received orchestrations, A_21 and A_22. Nothing strange is here except a parameter name. We choose the port of the sender, **A_1 **orchestration and S_SentFromA_1 port.
As you can see the Partner Orchestration parameter for the sender and receiver orchestrations is the same.
Testing
I dropped a test file in a file folder. There we go:
- A dropped file was received by B and by A_1
- A_1 sent a message forward.
- A message was received by B, A_21, A_22
http://code.msdn.microsoft.com/site/view/file/72400/1/DebugView.Forward.JPG
Let’s look at a context of a message sent by A_1 on the second step:
- A MessageType part. It is quite expected.
- A PartnerService, aParnerPort, an Operation. All those parameters were set up in the Partner Orchestration parameter on both bound ports.
http://code.msdn.microsoft.com/site/view/file/72401/1/A-1.MessageSent.Context.JPG
Now let’s see a subscription of the A_21 and A_22 orchestrations.
http://code.msdn.microsoft.com/site/view/file/72402/1/A_2x.Subscription.JPG
Now it makes sense. That’s why we have chosen such a strange value for the Partner Orchestration parameter of the sending orchestration.
Inverse Binding
This sample has three orchestrations: A_11, A_12 and A_2.
A_11 and A_12 are senders, A_2 is receiver.
http://code.msdn.microsoft.com/site/view/file/72403/1/All.jpg
How to set up the ports?
- All ports involved in the message exchange should be the same port type. It forces us to use the same operation and the same message type for the bound ports.
- This step as absolutely contra-intuitive. We have to choose a Partner Orchestration parameter for a receiving orchestration, A_2. The first strange thing is it is not a partner orchestration we have to choose but an orchestration port. But the most strange thing is we have to choose exactly this orchestration and exactly this port.It is not a port from the partner, sent orchestrations, A_11 or A_12, but it is A_2orchestration and R_SentToA_2 port.
- Now we have to choose a Partner Orchestration parameter for the sending orchestrations, A_11 and A_12. Nothing strange is here except a parameter name. We choose the port of the sender, A_2orchestration and **R_SentToA_2 **port.
Testing
I dropped a test file in a file folder. There we go:
- A dropped file was received by B, A_11 and by A_12
- A_11 and A_12 sent two messages forward.
- The messages were received by B, A_2
http://code.msdn.microsoft.com/site/view/file/72404/1/DebugView.Inverse.JPG
Let’s see what was a context of a message sent by A_1 on the second step:
- A MessageType part. It is quite expected.
- A PartnerService, a ParnerPort, anOperation. All those parameters were set up in the Partner Orchestration parameter on both bound ports.
http://code.msdn.microsoft.com/site/view/file/72405/1/A-1x.MessageSent.Context.JPG
Here is a subscription of the A_2 orchestration.
http://code.msdn.microsoft.com/site/view/file/72406/1/A-2.Subscription.JPG
Models
I had a hard time trying to explain the Partner Direct Ports in simple terms. I have finished with this model:
Forward Binding
Receivers know a Sender. Sender doesn’t know Receivers.
Publishers know a Subscriber. Subscriber doesn’t know Publishers.
1 –> 1
1 –> M
Inverse Binding
Senders know a Receiver. Receiver doesn’t know Senders.
Subscribers know a Publisher. Publisher doesn’t know Subscribers.
1 –> 1
M –> 1
Notes
Orchestration chain
It’s worth to note, the Partner Direct Port Binding creates a chain opened from one side and closed from another.
- **The Forward Binding: **A new Receiver can be added at run-time. The Sender can not be changed without design-time changes in Receivers.
- **The Inverse Binding: **A new Sender can be added at run-time. The Receiver can not be changed without design-time changes in Senders.
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.