Home > BizTalk ESB ToolKit > BizTalk ESB Toolkit 2.0 samples (Content based routing)

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 named ESBSample.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 to Actions.

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 to Admin

   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 on Abhijit.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 into EsbItineraryDb 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.

Advertisements
  1. Gopal paul
    September 14, 2010 at 8:57 am

    Excellent post to start learning BizTalk ESB Tool kit 2.0.
    Expect more samples…

    • September 14, 2010 at 9:22 am

      Thanks a lot Gopal…
      I will try to post few more samples using BizTalk ESB Toolkit 2.0 very soon!!!

  2. Chetan
    November 1, 2010 at 8:46 pm

    Hey Abhi gr8 post dude …. really very helpful…. since last month i was reading ESB Toolkit stuff….but nobody has shared sample code with superb description.
    Thanks a lot man 🙂

    hey if you dont mind can u plz post more samples on ESB Toolkit with orchestration
    resolver and transformation.

    Thanks in Advance

    • November 2, 2010 at 9:14 am

      Thanks Chetan…
      I am really happy that you liked my post.Will surely post more samples on ESB Toolkit.
      keep watching!!!

      Regards,
      Abhijit

  3. Chetan
    November 1, 2010 at 8:47 pm

    Also upload demo solution as well 🙂
    I hope i am not irritating u …

  4. vamsydhar
    April 18, 2011 at 9:54 am

    Hi Abhijit Excellent Post..Iam new to ESB
    Epecting more samples

  5. Abhijit
    June 3, 2011 at 6:39 am

    Abhijit, its a very useful post.
    Thanks a lot.

  6. Abhijit
    June 3, 2011 at 6:48 am

    One thing i missed to add, one will face a issue with BRE resolver for the DocumentType mismatch.
    To resolve the issue change the DocumentType of the Fact Schema to “Microsoft.Practices.ESB.ResolveProviderMessage” as ESB send the BRE with this overridden Documenttype for which the failure occurs.
    Also dont forget to set “Usemsg” to true in the BRE Resolver settings as shown.

  7. Dinesh
    June 8, 2011 at 11:54 am

    hi Abhijit,

    Very good post for beginner[who are new in ESB].

    I have one suggestion on ESB practices.

    Please share the list of different scenario esb biztalk application like above
    so we can try with same.
    It can be more helpful to us.

    Thanks,
    Dinesh

  8. July 1, 2011 at 7:21 am

    Hi Abhijit,

    Excellent post on ESB 2.0 by you and is very helpful for beginners like me.
    Mind blowing.

    I succeeded on this with some of the challenges. I would like to request Mr. Abhijit please post more ESB demos on orchestration and transformation so that one can touch the heaven of integration(SOA).

    Thank you very very much.
    Carry on…………..

  9. January 31, 2012 at 12:14 pm

    I have seen you have put it on Code Gallery. Good job. It is also included in the TechNet Wiki article: BizTalk Server Code Gallery Samples : http://social.technet.microsoft.com/wiki/contents/articles/6267.biztalk-server-code-gallery-samples.aspx.

  10. April 9, 2012 at 8:09 am

    Excellent Sir, Your article is my start kick to ESB. Thanks a lot.

  11. MEL
    June 1, 2012 at 1:01 pm

    Thank you Abhijit.
    This post really helps me to understand. Bat i have a problem, “Routing Failure Report for “ESBSample.OnRamp.Itinerary”.
    I have checked all the steps.
    Received location/ports are started/enabled.
    Policy deployed and ok (checked in the test utility of Business Rule Composer).
    In Biztalk administrator console, all the subscriptions seem ok (with lots of transportation protocols started).
    Itinerary deployed in the database, status 1.
    But … i don`t know what can i do… can anybody help me?
    Thanks in advange.
    MEL

    • June 4, 2012 at 6:25 am

      Hi MEL,

      I would suggest you to download the source code and compare your solution with this. If there is any mismatch, correct it. Redeploy and test.
      It should work.
      Rgds,
      Abhijit

  12. MEL
    June 6, 2012 at 3:00 pm

    Hi Abhijit
    i can`t use your code because i’m using Visual Studio 2010. I have typed again all the code, checked, deploay and everything…but allways obtain the same error msg “Routing failure … no subscribers were found …”
    I have exported the itinerary to xml and check it with the Itinerary test client, and it says “Message processes successfully” but the output files don`t appear in the folders.???
    Checking the SUBSCRIPTION DETAILS seem ok (IsRequestResponse=False, ServiceName, Service Type, Service State, InboundTransportationLocation, receivedPortName, receiveTransporType=FILE….
    AND in the Routing failure report i have the same things promoted (so seems ok) and the MessageType as http:://Abhijit.ESBSamples.Demo1.Schemas.Employee#Employee

    I tried the same example in other computer (instalation configuration or something extrange, but i have the same problems)….
    Any idea? i.m completely lost..
    MEL

  13. MEL
    June 7, 2012 at 7:13 am

    Hi Abhijit,
    firts of all thank a lot for being there answering. I feel completely lost in biztalk world, with a very few documentation an so on… YES you are true, i `ve just changed this and it works!!!! THANK YOU VERY MUCH…
    One question, could you recomend me any book, tutorial or something to learn about biztalk?. I have tried the ESB Labs, but there are no explanation… for example you knew about this flag/state ExportMode , this is like magic for me….
    I.m suppose to implement a pubish/subscriber application… a server will received data, and differents clients will subscribe to diferent things “dinamically”, so i was thinking about create programatically rules in a policy that governs the itinerary…. translating to your example, imagine a client program with a combobox for selecting one department and a edit box to type the folder name where you want to get the messages. Could be a good approach?
    Abhijit thank you so much.
    MEL

  14. Chandrasekhar
    April 20, 2015 at 4:51 pm

    Thank you for the fine example, Abhijit. I am seeing this error –

    The published message could not be routed because no subscribers were found. This error occurs if the subscribing orchestration or send port has not been enlisted, or if some of the message properties necessary for subscription evaluation have not been promoted. Please use the Biztalk Administration console to troubleshoot this failure.

    What could I be missing?

    Thanks and warm regards,
    Chandrasekhar G

  15. Chandrasekhar
    April 20, 2015 at 6:00 pm

    Hello, Abhijit, It worked on setting the Export Mode to Default, from Strict. Nice learning! Thank you and warm regards, Chandrasekhar G

  16. Abhishek Reddy
    September 17, 2015 at 6:01 pm

    Hey Abhi …….Awesome Explanation !! Thank you so much for sharing your knowledge here on ESB,Please post some more articles on EDI and ESB if you can.

    Thank you so much for your patience
    Regards,
    Abhishek.

  1. April 18, 2012 at 6:20 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: