How to: Dynamically Route a Message Based on Message Context Using a Business Rules Policy

This section demonstrates how to create an itinerary that determines message endpoints, based on message context properties, using a Microsoft BizTalk Server 2009 Business Rules Engine (BRE) policy, and then routes the message using the Microsoft BizTalk Server 2009 FILE adapter.

In this How-to topic, you will complete the following steps:

  • Create a business rules policy to evaluate message type.
  • Create an itinerary routing slip to dynamically route using a business rules policy.
  • Test the itinerary using the Itinerary Test Client sample application.

The procedures in this How-to topic require the completion of the Prerequisites for the Development Activities.

To create a BRE policy to route a message using message context properties

  1. Click Start on the taskbar, point to All Programs, point to Microsoft BizTalk Server 2009, and then click Business Rule Composer.
  2. In Policy Explorer, right-click Policies, and then click Add New Policy. Name the policy RouteBasedOnMessageType.

To add a routing rule for North American orders

  1. In the RouteBasedOnMessageType policy, right-click Version 1.0 (not saved), and then click Add New Rule. Name the rule SetNAOrderEndpoint.
  2. In the Rule window, right-click Conditions, point to Predicates, and then click Equal.
  3. In Facts Explorer, expand the ESB.ContextInfo vocabulary, expand Version 1.0, and then drag the Context Message Type fact to the argument1 node under Conditions.
    Ee236707.note(en-US,BTS.10).gifNote:
    The BizTalk ESB Toolkit includes several vocabularies that can be used for creating rules. Some of these should be replaced or augmented with your own vocabularies. For example, the DynamicRunTimeMaptypes policy has definitions for the maps provided in the GlobalBank samples.

  4. Click the argument2 node, and then type http://globalbank.esb.dynamicresolution.com/northamericanservices/#OrderDoc
  5. In Facts Explorer, expand the ESB.EndPointInfo vocabulary, expand Version 1.0, and then drag the Set End Point Outbound Transport Location definition to Actions.
  6. Click <empty string>, and then type C:\HowTos\Out\NorthAmerica%MessageID%.xml
  7. From Facts Explorer, drag the Set End Point Outbound Transport Type definition to Actions.
  8. In Facts Explorer, expand the ESB.TansportTypes vocabulary, expand Version 1.0, and then drag the Adaptor Providers definition to <empty string>.
  9. In the Actions pane, expand the Adaptor Providers drop-down list, and then click FILE.

To publish and deploy the policy

  1. In Policy Explorer, under the RouteBasedOnMessageType policy, right click Version 1.0 (not saved), and then click Publish.
  2. In Policy Explorer, under the RouteBasedOnMessageType policy, right click Version 1.0 - Published, and then click Deploy.

To create an ESB itinerary domain-specific language (DSL) model

  1. In Microsoft Visual Studio 2008, open C:\HowTos\Patterns\Patterns.sln.
  2. In Solution Explorer, right-click the ItineraryLibrary project, point to Add, and then click New Itinerary.
  3. In the Name box, type MessageType, and then click Add.

To configure the properties of the itinerary

  1. In Visual Studio, click the design surface of MessageType.itinerary. In the MessageType Properties window, configure the following properties:
    1. In the Model Exporter drop-down list, click XML Itinerary Exporter.
    2. In the Extender Settings section, next to the Itinerary XML file property, click the ellipsis button (...).
    3. In the Select XML File dialog box, in the File name box, type C:\HowTos\Itineraries\MessageType, and then click Save.
      Ee236707.note(en-US,BTS.10).gifNote:
      This step enables you to export the itinerary as XML to a local file location. Exporting an itinerary to a local file location, instead of to the itinerary database, enables testing of 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

  1. From the Toolbox, drag an On-Ramp model element to the design surface. In the OnRamp1 Properties window, configure the following properties:
    1. Click the Name property, and then type ReceiveOrders.
    2. In the Extender drop-down list, click On-Ramp ESB Extender.
    3. In the BizTalk Application drop-down list, click Microsoft.Practices.ESB.
    4. In the Receive Port drop-down list, click OnRamp.Itinerary.
  2. From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it to the right of the On-Ramp model element. In the ItineraryService1 Properties window, configure the following properties:
    1. Click the Name property, and then type BreRoute.
    2. In the Itinerary Service Extender drop-down list, click Messaging Extender.
      Ee236707.note(en-US,BTS.10).gifNote:
      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.

    3. In the Container drop-down list, expand ReceiveOrders, and then click Receive Handlers.
    4. In the Service Name drop-down list, click Microsoft.Practices.ESB.Services.Routing.
  3. Right-click the Resolver collection of the BreRoute model element, and then click Add new Resolver. In the Resolver1 Properties window, configure the following properties:
    1. Click the Name property, and then type ByMessageType.
    2. In the Resolver Implementation drop-down list, click Bre Resolver Extension.
    3. In the Policy drop-down list, click RouteBasedOnMessageType v 1.0.
  4. In the Toolbox, click Connector. Drag a connection from the ReceiveOrders model element to the BreRoute model element.
  5. From the Toolbox, drag an Off-Ramp model element to the design surface, and then place it to the right of the BreRoute model element. In the OffRamp1 Properties window, configure the following properties:
    1. Click the Name property, and then type SendBasedOnType.
    2. In the Extender drop-down list, click Off-Ramp ESB Extender.
    3. In the BizTalk Application drop-down list, click GlobalBank.ESB.
    4. In the Send Port drop-down list, click DynamicResolutionOneWay.
  6. From the Toolbox, drag an Itinerary Service model element to the design surface, and then place it between the BreRoute model element and the SendBasedOnType model element. In the ItineraryService1 Properties window, configure the following properties:
    1. Click the Name property, and then type SendPortFilter.
    2. In the Itinerary Service Extender drop-down list, click Off-Ramp Extender.
    3. In the Off-Ramp drop-down list, expand SendBasedOnType, and then click Send Handlers.
  7. In the Toolbox, click Connector. Drag a connection from the BreRoute model element to the SendPortFilter model element.
  8. In the Toolbox, click Connector. Drag a connection from the SendPortFilter model element to the SendBasedOnType model element.

To export the model for use with the Itinerary Test Client

  1. In Visual Studio, right-click the design surface of the MessageType itinerary, and then click Export Model.
    Ee236707.note(en-US,BTS.10).gifNote:
    The XML version of the itinerary opens in Visual Studio.

  2. Save all project artifacts.
  3. In Windows Explorer, browse to C:\HowTos\Itineraries and notice the creation of your itinerary XML (MessageType.xml).

To test the itinerary

  1. 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).
  2. In the Itinerary Test Client, clear the Use WCF Service check box, and then click Load Itinerary.
  3. In the Open Itinerary File dialog box, browse to C:\HowTos\Itineraries. Select MessageType.xml, and then click Open to load the itinerary.
  4. Click OK to clear the Itinerary Loaded Successfully message.
  5. In the Itinerary Test Client, click the ellipsis button (...) next to the Load Message box.
  6. In the Select XML Document to load dialog box, browse to C:\HowTos. Select NAOrderDoc.xml, and then click Open to load the test message.
  7. Click the Submit Request button. When the test completes, click OK to dismiss the confirmation that appears.
  8. In Windows Explorer, browse to C:\HowTos\Out\. Verify that the NorthAmerica%MessageID%.xml message has been written to the directory.

Community Additions

ADD
Show: