Share via


BizTalk Server: Implementation of Routing Slip Pattern Using ESB Toolkit 2.1

The Microsoft BizTalk ESB Toolkit extends the capabilities of BizTalk Server to support a loosely coupled messaging architecture. This article demonstrated how to implement routing slip pattern using BizTalk ESB Toolkit 2.1 and Business rules policy on top of BizTalk Server 2010.

Introduction

Routing slip pattern describes a scenario where we route a message consecutively through a series of processing steps when the sequence of steps is not known at design-time and may vary for each message.

Business Case: XML messages pertaining to Employee schema are picked by BizTalk from a specified file location and routed through a series of processing steps (Itinerary) based on the value of department.  For example if the department is ‘Admin’ then ‘ForAdmin’ itinerary will be selected and if ‘HR’ then ‘ForHR’ itinerary will be selected.

Solution Walkthrough: This solution consists of following artifacts:

  • Itineraries( ForHR.itinerary and ForAdmin.itinerary) – Series of processing steps defined for HR and Admin employees respectively.
  • Business rule policy (SelectItineraryBasedOnDept) – Used to select the correct itinerary based on the value of department.
  • XML Schema( Employee.xsd)

Building the Sample

Following steps need to follow to develop the BizTalk solution:

1. Open BizTalk Administrator console and create an application named “ESBSamples”. Add a reference of the application “Microsoft.Practices.ESB” to the ESBSamples project.

Note: Microsoft.Practices.ESB is the default application for ESB related artifacts which get automatically created during the configuration of ESB Toolkit 2.1

2. Right click on Send ports under the application ESBSamples and Create a new dynamic one way send port named “DynamicSendToOutput”. Create the following filters as shown below:

 http://code.msdn.microsoft.com/site/view/file/59783/1/SendPort.jpg

3. Create a Receive port ESBSample.OnRamp.Itinerary and a Receive location named ESBSample.OnRamp.Itinerary.FILE and configure this as:

URI: C:\Abhijit.ESBSamples\Input\.xml

Receive Pipeline: ItinerarySelectReceiveXml having ItineraryFactKey = Resolver.Itinerary

ResolverConnectionString = BRI:\policy=SelectItineraryBasedOnDept;useMsg=true;recognizeMessageFormat=true;

Here SelectItineraryBasedOnDept is the name of the Business Rule Policy which we will be creating from step- (8)

http://code.msdn.microsoft.com/site/view/file/59784/1/rcvpipeline.jpg

4. Now open visual studio 2010, create a blank solution named “Abhijit.ESBSamples”.

5. Add an Empty BizTalk Server project named “Abhijit.ESBSamples.Demo2.Schemas” and a BizTalk ESB Itinerary Designer named “Abhijit.ESBSamples.Demo2.Itinerary”.

http://code.msdn.microsoft.com/site/view/file/59785/1/SolutionDemo2.jpg

6. Right click on the schema project and add a schema named Employee.xsd having following fields as shown below in the image:

 http://code.msdn.microsoft.com/site/view/file/59786/1/Employee.jpg

7. After signing the project deploy it to application named “ESBSamples” the one we have created in step-1.

Create the Business Rule Policy

8. Now open Business Rule Composer and create a policy named “SelectItineraryBasedOnDept

9. In the SelectItineraryBasedOnDept policy, right-click and Add New Rule. Name the rule to ”SelectAdminItinerary”.

10. In Facts Explorer, click the XML Schemas tab, right-click Schemas, and then click browse

to Employee.xsd under the folder C:\C#\Abhijit.ESBSamples\Abhijit.ESBSamples.Demo2.Schemas\ and open it.

11. In fact explorer, click on Employee.xsd and change the Document Type property to

Abhijit.ESBSamples.Demo2.Schemas.Employee.

12. In the Rule window, right-click Conditions, point to Predicates, and then click Equal.

13. From Facts Explorer, drag the Department element to the argument1 node under Conditions.

14. Click the argument2 node, and then type Admin.

15. From Facts Explorer, drag the Set Itinerary Name definition under the vocabulary ESB.Itinerary to Actions.

16. Click and then type ForAdmin to <empty string>.

http://code.msdn.microsoft.com/site/view/file/59787/1/BREPolicy.jpg

     Similarly add one more rule named “ForHR” having following Conditions and Actions

      Rule: SelectHRItinerary

      Conditions:
**
**      Abhijit.ESBSamples.Demo2.Schemas.Employee:/Employee/Department is equal to HR

      Actions:
**
**     Set Itinerary Name to ForHR.

17. Publish and deploy the policy to Rule Engine database.

Create the “ForAdmin” Itinerary

18. Now switch to Visual studio solution and right click on Abhijit.ESBSamples.Demo2.Itinerary project and add an Itinerary named “ForAdmin.Itinerary

19. Design the Itinerary as below:

http://code.msdn.microsoft.com/site/view/file/59788/1/ForAdminIti.jpg

Here first shape is the On-Ramp(RcvAdminEmployee) and for the properties of this refer the below image.

http://code.msdn.microsoft.com/site/view/file/59789/1/Itin1.jpg

Last shape is the Off-Ramp(SndAdminEmployeeMsg) and for the properties of this shape refer the below image.

http://code.msdn.microsoft.com/site/view/file/59790/1/Itin2.jpg

Other two middle shapes are Itinerary service, one is for Messaging Extender(SendToFile) and other is for off-Ramp Extender(SetDestinationInfo).

For the properties of SendToFile shape, refer the below image

 http://code.msdn.microsoft.com/site/view/file/59791/1/Itin3.jpg

And for the properties of the Static Resolver used in the Itinerary service, refer the below image.

 http://i1.code.msdn.s-msft.com/implementation-of-routing-8b187f5e/image/file/59848/1/adminstatic.jpg

For the properties of off-Ramp Extender(SetDestinationInfo), refer the below image

 http://code.msdn.microsoft.com/site/view/file/59793/1/Itin5.jpg

20. Now Right-Click on the Itinerary designer and click on validate. You might get an error with description: A X509 Certificate is required in the model property ‘EncryptionCertificate’ to encrypt any sensitive property in the designer.

To get rid of this error you need to set the value of ‘Require Encryption Certificate’ to false.

21. Set the model exporter of the Itinerary as Database Itinerary Exporter and Itinerary status as Deployed.

http://code.msdn.microsoft.com/site/view/file/59794/1/Itin6.jpg

22. Right-Click on Itinerary designer and click on Export model to store the Itinerary into EsbItineraryDb database.

Create the “ForHR” Itinerary

23. Design the Itinerary as below image

http://code.msdn.microsoft.com/site/view/file/59795/1/ForHR.jpg

Configuration properties for each shape is similar to “ForAdmin” itinerary. Only difference is in value of the ‘Transport Location’ of the Static Resolver used in ‘SendToFile’ itinerary service.

 http://i1.code.msdn.s-msft.com/implementation-of-routing-8b187f5e/image/file/59849/1/hrstatic.jpg

Right-Click on Itinerary designer and click on Export model to store the Itinerary into EsbItineraryDb database.

Test the Application

  • From the BizTalk administrator console under the application “ESBSamples” enable the Receive location and start the send port. You might need to change the Receive location and send locations as per your environment.
  • Now drop your sample files into “C:\Abhijit.ESBSamples\Input\ “ folder. If everything configured properly then you will see output file either in location “C:\Abhijit.ESBSamples\Output\HR\ or “C:\Abhijit.ESBSamples\Output\Admin\ based on the value of the department field of the input messages.

See Also

Another important place to find an extensive amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.