How to: Implement Content-Based Routing Using Message Context Properties
Goal
This section demonstrates how to use the Microsoft BizTalk ESB Toolkit Itinerary Designer to create an itinerary that selects a message recipient based on the message context property and then routes a message to that recipient using the Itinerary Broker messaging service.
In this topic, you will complete the following steps:
Create an itinerary with an itinerary broker and two routing services with static resolvers.
Test the itinerary using the Itinerary Test Client sample application.
Note
No orchestration-based broker service is provided in the current implementation.
Prerequisites
The procedures in this How-to topic require the completion of the Prerequisites for the Development Activities.
Steps
To create an ESB Itinerary DSL model
In Visual Studio, open C:\HowTos\Patterns\Patterns.sln.
In Solution Explorer, right-click ItineraryLibrary, point to Add, and then click New Itinerary.
In the Add New Item dialog box, click ItineraryDsl in the Templates pane.
In the Name box, type ChoiceRouter, and then click Add.
To configure the properties of the itinerary
In Visual Studio, click the design surface of the ChoiceRouter itinerary. In the ChoiceRouter Properties window, configure the following properties:
In the Model Exporter drop-down list, click XML Itinerary Exporter.
In the Extender Settings section, click the ellipsis button (...) next to the Itinerary XML file property.
In the Export Mode property drop-down list, click Strict.
In the Select XML File dialog box, type C:\HowTos\Itineraries\ChoiceRouter in the File name box, and then click Save.
Note
This step enables you to export the itinerary as XML to a local file location. By exporting an itinerary to a local file location, instead of to the itinerary database, you can test the itinerary using the ESB Test Client application. You will complete this process later in this How-to topic.
To define the structure of the itinerary
From the Toolbox, drag an On-Ramp model element to the design surface. In the OnRamp1 Properties window, configure the following properties:
Click the Name property, and then type ReceiveNAOrder.
In the Extender drop-down list, click On-Ramp Extender.
In the BizTalk Application drop-down list, click Microsoft.Practices.ESB.
In the Receive Port drop-down list, click OnRamp.Itinerary.
From the Toolbox, drag an Itinerary Broker Service model element to the designer surface, and then place it to the right side of the On-Ramp model element. In the ItineraryBrokerService1, configure the following properties:
Click the Name property, and then type RouteBrokerService.
In the Extender drop-down list, click Messaging Broker Extender.
In the Container drop-down list, expand ReceiveNAOrder, and then click Receive Handlers.
In the Service Name drop-down list, click Microsoft.Practices.ESB.Itinerary.Services.Broker.MessagingBroker.
Right-click the Filter collection, and then click Add new Filter. In the Filter1 Properties window, configure the following properties:
Click the Name property, and then type ASMXFilter.
Click the Filter Implementation drop-down list, and then click XPath Filter.
Click the Expression property, and then type count(/ContextProperties/Property[@name='InboundTransportLocation'][contains(., 'ProcessItinerary.asmx')]) > 0.
Right-click the Filter collection, and then click Add new Filter. In the Filter1 Properties window, configure the following properties:
Click the Name property, and then type WCFFilter.
Click the Filter Implementation drop-down list, and click XPath Filter.
Click the Expression property, and then type count(/ContextProperties/Property[@name='InboundTransportLocation'][contains(., 'ESB.ItineraryServices.WCF')]) > 0.
Right-click the Resolver collection of the RouteBrokerService model element, and then click Add new Resolver. In the Resolver1 Properties window, configure the following properties:
Click the Name property, and then type ResolverBrokerRoute.
In the Resolver Implementation drop-down list, click MessageContext Resolver Extension.
In the Toolbox, click Connector. Drag a connection from the ReceiveNAOrder model element to the RouteBrokerService model element.
From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it under the RouteBrokerService model element. In the ItineraryService1 Properties window, configure the following properties:
Click the Name property, and then type RouteToFileFromASMX.
In the Itinerary Service Extender drop-down list, click Messaging Extender.
Note
This property defines that the process will take place in a pipeline (messaging). Alternately, if the process will take place in an orchestration, set the Itinerary Service Extender property to Orchestration Extender.
In the Container drop-down list, expand ReceiveNAOrder, and then click Receive Handlers.
In the Service Name drop-down list, click Microsoft.Practices.ESB.Services.Routing.
Right-click the Resolver collection of the RouteToFileFromASMX model element, and then click Add new Resolver. In the Resolver1 Properties window, configure the following properties:
Click the Name property, and then type ResolverFromAsmx.
In the Resolver Implementation drop-down list, click Static Resolver Extension.
In the Transport Name drop-down list, click FILE.
Click the Transport Location property, and then type c:\howtos\out\asmx%MessageId%.xml.
From the Toolbox, drag an Off-Ramp model element to the design surface, and then place it to the right of the RouteToFileFromASMX model element. In the OffRamp1 Properties window, configure the following properties:
Click the Name property, and then type SendASMXOrder.
In the Extender drop-down list, click Off-Ramp ESB Extender.
In the BizTalk Application drop-down list, click GlobalBank.ESB.
In the Send Port drop-down list, click DynamicResolutionOneWay.
From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it between the RouteToFileFromASMX model element and the SendASMXOrder model element. In the ItineraryService1 Properties window, configure the following properties:
Click the Name property, and then type SendPortFilterASMX.
In the Itinerary Service Extender drop-down list, click Off-Ramp Extender.
In the Off-Ramp drop-down list, expand SendASMXOrder, and then click Send Handlers.
In the Toolbox, click Connector. Drag a connection from the RouteToFileFromASMX model element to the SendPortFilterASMX model element.
In the Toolbox, click Connector. Drag a connection from the SendPortFilterASMX model element to the SendASMXOrder model element.
From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it to the right of RouteBrokerService model element. In the ItineraryService1 Properties window, configure the following properties:
Click the Name property, and then type RouteToFileFromWCF.
In the Itinerary Service Extender drop-down list, click Messaging Extender.
Note
This property defines that the process will take place in a pipeline (messaging). Alternately, if the process will take place in an orchestration, set the Itinerary Service Extender property to Orchestration Extender.
In the Container drop-down list, expand ReceiveNAOrder, and then click Receive Handlers.
In the Service Name drop-down list, click Microsoft.Practices.ESB.Services.Routing.
Right-click the Resolver collection of the RouteToFileFromWCF model element, and then click Add new Resolver. In the Resolver1 Properties window, configure the following properties:
Click the Name property, and then type ResolverFromWCF.
In the Resolver Implementation drop-down list, click Static Resolver Extension.
In the Transport Name drop-down list, click FILE.
Click the Transport Location property, and then type c:\howtos\out\wcf%MessageId%.xml.
From the Toolbox, drag an Off-Ramp model element to the design surface, and then place it to the right of the RouteToFileFromWCF model element. In the OffRamp1 Properties window, configure the following properties:
Click the Name property, and then type SendWCFOrder.
In the Extender drop-down list, click Off-Ramp ESB Extender.
In the BizTalk Application drop-down list, click GlobalBank.ESB.
In the Send Port drop-down list, click DynamicResolutionOneWay.
From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it between the RouteToFileFromWCF model element and the SendWCFOrder model element. In the ItineraryService1 Properties window, configure the following properties:
Click the Name property, and then type SendPortFilterWCF.
In the Itinerary Service Extender drop-down list, click Off-Ramp Extender.
In the Off-Ramp drop-down list, expand SendWCFOrder, and then click Send Handlers.
In the Toolbox, click Connector. Drag a connection from the RouteToFileFromWCF model element to the SendPortFilterWCF model element.
In the Toolbox, click Connector. Drag a connection from the SendPortFilterWCF model element to the SendWCFOrder model element.
From the Toolbox, drag an Itinerary Outport model element to right border of RouteBrokerService. In the ItineraryBrokerOutPort1 Properties window, configure the following properties:
Click the Name property, and then type WCF Port.
In the Filter drop-down list, click WCFFilter.
In the Resolver drop-down list, click ResolverBrokerRoute.
From the Toolbox, drag an Itinerary Outport model element to the bottom border of RouteBrokerService. In the ItineraryBrokerOutPort1 Properties window, configure the following properties:
Click the Name property, and then type ASMX Port.
In the Filter drop-down list, click ASMXFilter.
In the Resolver drop-down list, click ResolverBrokerRoute.
In the Toolbox, click Connector. Drag a connection from the WCF Port model element to the RouteToFileFromWCF model element.
In the Toolbox, click Connector. Drag a connection from the ASMX Port model element to the RouteToFileFromASMX model element.
To export the model for use with the Itinerary Test Client
Note
You will need to export the itinerary twice: one time in XML and one time to the database to test the routing through the broker.
In Visual Studio, right-click the design surface of the ChoiceRouter itinerary, and then click Export Model.
Note
The XML version of the itinerary opens in Visual Studio.
In Windows Explorer, browse to C:\HowTos\Itineraries, and then notice the creation of your itinerary XML (ChoiceRouter.xml).
In Visual Studio, right-click the design surface of the ChoiceRouter itinerary, and then click Export Model.
In the Properties window, click Database Itinerary Exporter in the Model Exporter drop-down list.
In the Properties window, set the Itinerary Database property connection string to point to the itinerary database.
In the Itinerary Status property drop-down list select Deployed.
In Visual Studio, right-click the design surface of the ChoiceRouter itinerary, and then click Export Model.
To test the itinerary
Open the Itinerary Test Client sample application using the shortcut created during the Prerequisites for the Development Activities (C:\HowTos\ESB.Itinerary.Test.exe - Shortcut).
In the Itinerary Test Client, clear the Use WCF Service check box, and then click Load Itinerary.
In the Open Itinerary File dialog box, browse to C:\HowTos\Itineraries. Select ChoiceRouter.xml, and then click Open to load the itinerary.
Click OK to close the "Itinerary Loaded Successfully" message.
In the Itinerary Test Client, click the ellipsis button (...) next to the Load Message box.
In the Select XML Document to load dialog box, browse to C:\Patterns\HowTos. Select NAOrderDoc.xml, and then click Open to load the test message.
Click the Submit Request button. When the test completes, click OK to close the confirmation message that appears.
In Windows Explorer, browse to C:\HowTos\Out. Verify that the ASMX%MessageID%.xml messages have been written to this directory.
Click the Itinerary Test client Use WCF Service check box. In the Itinerary Name box, type ChoiceRouter, and then click the Submit Request button. When the test completes, click OK to close the confirmation message.
In Windows Explorer, browse to C:\HowTos\Out. Verify that the WCF%MessageID%.xml messages have been written to this directory.
Additional Resources
For more information, see the following related topics: