BizTalk ESB Toolkit 2.0 samples (Content based routing)

In this post, I am going to demonstrate how to achieve content based routing using BizTalk ESB Toolkit 2.0 and Business rules policy.
In the sample Business rule policy(RouteBasedOnDepartment) is used to set the endpoint information of the incoming employee messages based on the value of the department field in the incoming message.
The Itinerary(RouteBasedOnDept.Itinerary) contains ON-Ramp, OFF-RAMP and Routing service with BRE resolver to dynamically route the message.
Steps to create and test the application:
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.0
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:
SendPort
3.Create a Receive port ESBSample.OnRamp.Itinerary and a Receive location namedESBSample.OnRamp.Itinerary.FILE and configure this as:
URI: C:\Abhijit\Abhijit.ESBSamples\Input\ *.xml
Receive Pipeline: ItinerarySelectReceive having ItineraryFactKey = Resolver.Itinerary
ResolverConnectionString = ITINERARY:\\name=RouteBasedOnDept;version=1.0
Here RouteBasedOnDept is the name of the Itinerary which we will be creating from step- (21)
ReceiveLocation
4. Now open visual studio 2008, create a blank solution named “Abhijit.ESBSamples”.
5. Add a BizTalk project named “Abhijit.ESBSamples.Demo1.Schemas” and a C# class library named “Abhijit.ESBSamples.Demo1.Itinerary”.
Solution

6. Right click on the schema project and add a schema named Employee.xsd having following fields as shown below in the image:
EmployeeSchema
7. After signing the project deploy it to application named “ESBSamples” the one we have created in step-1.
8. Now open Business Rule Composer and create a policy named “RouteBasedOnDept
9. In the RouteBasedOnDept policy, right-click and Add New Rule. Name the rule to “ForAdmin”.
10. In Facts Explorer, click the XML Schemas tab, right-click Schemas, and then click Browse.
to Employee.xsd under the folder C:\Abhijit\Abhijit.ESBSamples\Abhijit.ESBSamples.Demo1.Schemas\ and open it.
11. In fact explorer click on Employee.xsd and change the Document Type property to
Abhijit.ESBSamples.Demo1.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 End Point Outbound Transport Location definition under the vocabulary ESB.EndPointInfo to Actions.
16. Click and then type C:\Abhijit\Abhijit.ESBSamples\Output\Admin \%MessageID%.xml.
17. From Facts Explorer, drag the Set End Point Outbound Transport Type definition toActions.
18. From Facts Explorer, drag the Adaptor Providers definition under ESB.TransportTypes, vocabulary to <empty string>.
19. In the Actions pane, expand the Adaptor Providers drop-down list, and then click FILE.
BRE
     Similarly add two more rules name “ForHR” and “ForOthers” having following Conditions and Actions respectively.
      Rule: ForHR
      Conditions:      Abhijit.ESBSamples.Demo1.Schemas.Employee:/Employee/Department is equal to HR
      Actions:      Set End Point Outbound Transport Location to C:\Abhijit\Abhijit.ESBSamples\Output\HR\%MessageID%.xml
      Set End Point Outbound Transport Type to FILE
    Rule:ForOthers
      Conditions:     Abhijit.ESBSamples.Demo1.Schemas.Employee:/Employee/Department is not equal to HR
                                                                       AND
    Abhijit.ESBSamples.Demo1.Schemas.Employee:/Employee/Department is not equal toAdmin
   Actions:   Set End Point Outbound Transport Location to C:\Abhijit\Abhijit.ESBSamples\Output\Others\% MessageID%.xml
   Set End Point Outbound Transport Type to FILE
20. Publish and Deploy the policy to RuleEngine database.
21. Now switch to Visual studio solution and right click onAbhijit.ESBSamples.Demo1.Itinerary project and add an Itinerary named “RouteBasedOnDept.Itinerary
22. Design the Itinerary as below:
Itinerary
Here first shape is the On-Ramp and for the properties of this refer the below image.
RCVEmployeeProperties
Last shape is the Off-Ramp and for the properties of this shape refer the below image.
SndEmployeeProperties
Middle shape is the Itinerary service shape and for the properties of this shape refer the below image.
SetDestinationInfoProperties
and for the properties of the BRE Resolver used in the Itinerary service, refer the below image.
BREResolverProperties
23. 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.
ErrorDescription
To get rid of this error you need to disable the X.509 certificate validation from the registry:
In the Registry Editor, navigate to the subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\BizTalk ESB Toolkit\2.0\Designer, and then set the RequireX509Certificate property value to false.
24. Set the model exporter of the Itinerary as Database Itinerary Exporter and Itinerary status as Deployed.
ItineraryDeployed
25. Right-Click on Itinerary designer and click on Export model to store the Itinerary intoEsbItineraryDb database.
Test the solution:
From the BizTalk administrator console under the application “ESBSamples” enable the Receive location and start the send port.
Now drop all the three files from the folder “C:\Abhijit\Abhijit.ESBSamples\Sample\ “ into “C:\Abhijit\Abhijit.ESBSamples\Input\ “ folder. If everything configured properly then you will see one file each in the locations “C:\Abhijit\Abhijit.ESBSamples\Output\HR\” ,
“C:\Abhijit\Abhijit.ESBSamples\Output\Admin\” and “C:\Abhijit\Abhijit.ESBSamples\Output\Others\” based on the value of the Department field of the input messages.
Download the SourceCode:
To download the code please  Click here
Note:Change the extension of the file from .doc to .zip and extract it into your C: drive.

Ref: https://abhijitmahato.wordpress.com/2010/09/10/biztalk-esb-toolkit-2-0-samples-content-based-routing/

Post a Comment

0 Comments