Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What Is Content Based Routing With Mule ESB

What Is Content Based Routing With Mule ESB

What Is Content Based Routing With Mule ESB

Avatar for Jitendra Bafna

Jitendra Bafna

May 06, 2017
Tweet

More Decks by Jitendra Bafna

Other Decks in Technology

Transcript

  1. Content Based routing Content-Based routing is used to examine the

    message and route message to correct channel or destination depending on a message content. You should always used Content-based route when you want to route message to correct destination. The routing can be based on various criteria like existence of fields, specific fields etc. For example, If you want to route the Purchase Order to different recipient on basis of Customer ID. If Customer ID=1 then send purchase order message to XYZ Limited via SFTP protocol. If Customer ID=2 then send purchase order message to PQR Limited via HTTP. You can add more recipient depending on your requirements
  2. Content Based routing Anypoint Studio provided Choice Router to achieve

    content-based routing. Choice router will always choose one and one route only. If no route matches, then default route is used. Let's walkthrough how you can implement content-based routing with Anypoint Studio. We will design solution where we will get POST request over HTTP with query param CustID and depending on CustID value the message will route to correct recipient.
  3. Setting of Message Source Place HTTP listener to the message

    source region in the Mule flow and configure the http listener. You need to send CustID as a query param (e.g. http://localhost:8081/CBR?CustID=1).
  4. Store Query Parameter To Flow Variable You need to store

    the query parameter CustID in flow variable. So you can use that flow variable for routing message to correct recipient.
  5. Choice Router Place Choice flow control after variable transformer. Choice

    flow control will route message to correct destination depends on custID value. Below table is showing how routes has been setup in choice flow control. When Route Message to #[flowVars.custID=='1'] File + Set Payload=Message sent to file location #[flowVars.custID=='2'] JMS + Set Payload=Message sent to jms Default Set Payload = No destination found
  6. Testing the Application • You can use Postman to test

    the application by sending request to Mule flow and make sure you are passing the CustID as a query param as it is important parameter to decide the routing to correct destination. • Case 1: • You can post http message to Mule flow and pass CustID=1 as query param and this request will route to File and Set Payload 'Message sent to file location'.
  7. Testing the Application • Case 2: • You can post

    http message to Mule flow and pass CustID=2 as query param and this request will route to JMS Topic and Set Payload 'Message sent to jms'.
  8. Testing the Application • Case 3: • You can post

    http message to Mule flow and pass CustID=3 or other than 1 and 2 as query param and this request will Set Payload 'No destination found'.