Routing is the process of transmitting messages between various artefacts namely Receive Ports, Send Ports and Orchestration within BizTalk Messaging Engine. It can be regarded as the heart of BizTalk Messaging Engine. To route any message inside BizTalk, the message must have a promoted property associated with it.
There are two types of promoted properties based on types they are derived from namely,
- Message Context Property Base
- Message Data Property Base or Message Part Property Base
As soon as a message is received, BizTalk will automatically promote various properties such as Adapter, Receive Port and Location Details. Also, if we use Pipeline Components such as XML or Flat-File Disassembler, additional properties will be promoted such as MessageType. Such properties promoted by default by BizTalk are derived from the Message Context Property base. Routing based on these properties is called Context based Routing. And Routing based on the latter type of promoted properties is called Content based Routing.
Any Element or Attribute promoted using BizTalk Schema Editor manually is by default derived from the Message Data Property Base. Routing based on these properties is called Content based Routing.
You can find all the default context properties promoted by BizTalk engine in the “schemas” tab of “<All Artifacts>” in BizTalk Server Administration Console.
Different Sources used for Content/Context Based Routing:
- Based on the content of the document
- Based on the information contained in the envelop of the document
- Based on the configuration information from the receive location/port (which are either populated by default or by BizTalk Engine)
- Based on the information populated through custom pipeline components
- Based on the information populated when a correlation set is initialized inside Orchestration send ports
Different Scenarios where Context/Content based routing are used:
- When the message is not processed but just pass-through transmitted
- When orchestration is not used
- When orchestration uses Direct binding logical ports
I will try to explain each type of routing with an example.
Let us start with Content Based Routing,
Let us say that we receive purchase orders which have several fields. All the messages received are in XML format and are placed in an inbound folder for processing
We need to route messages to trading partner A and trading partner B based on the order amount. Any purchase order with Total order amount > = 1000 will be routed to trading partner A and anything with an order amount lesser than 1000 will be routed to trading partner B.
In this example we are using a property field (POTotalAmount) defined within a schema to route messages. As said earlier any elements within schema are not promoted automatically by BizTalk engine, we need to promote the required property manually (either as Distinguished Field/Property Field). In our scenario we need to promote “TotalOrderAmount” field to access it in messaging service for routing.
I am doing a quick promotion to promote the “POTotalAmount” field.
PropertySchema with promoted POTotalAmount field:
In the POTotalAmount property schema, set the “PropertySchemaBase” to “MessageContextPropertyBase”.
PurchaseOrder Schema with “POTotalAmount” field highlighted with property promotion
I am creating a receive port and a receive location to pick up any xml messages dropped in the inbound folder
Receive Port and Receive Location Configuration:
Two send ports needs to be created to route messages to either trading partner A or trading partner B based on the POTotalAmount.
Creating a new Static One-Way Send Port:
SendPort A Configuration:
In Send PortA configure the Filters expression to send messages where POTotalAmount is >= 1000
Also Send PortB needs to be configured to send messages where POTotalAmount<1000
SendPort B Configuration:
Context Based Routing
As discussed earlier BizTalk messaging engine automatically promotes various properties as soon as the message is received. Routing of messages based on the default promoted property of BizTalk rule engine is called as Context Based Routing.
Let us consider a simple example to demonstrate the property.
We are receiving “PurchaseOrder” and “CustomerInformation” from different trading partner and based on the ReceicePort name (i.e. PurchaseOrder or CustomerInformation) messages will be routed to PortA or PortB. Messages received from “PurchaseOrder” receive port will be sent to “PortA” and messages received from “CustomerInformation” receive port will be sent to “PortB”.
PurchaseOrder Receive Port and Receive Location Configuration:
CustomerInformation Receive Port and Receive Location Configuration:
PurchaseOrder Send Port A Configuration:
CustomerInformation Send Port B Configuration: