10
WHAT IS CONTENT-BASED ROUTING WITH MULESOFT

What is Content Based Routing With Mulesoft

Embed Size (px)

Citation preview

Page 1: What is Content Based Routing With Mulesoft

WHAT IS CONTENT-BASED ROUTING WITH MULESOFT

Page 2: What is Content Based Routing With Mulesoft

CONTENT BASED ROUTINGContent-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

Page 3: What is Content Based Routing With Mulesoft

CONTENT BASED ROUTINGAnypoint 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 paramCustID and depending on CustID value the message will route to correct recipient.

Page 4: What is Content Based Routing With Mulesoft

SETTING OF MESSAGE SOURCEPlace 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).

Page 5: What is Content Based Routing With Mulesoft

STORE QUERY PARAMETER TO FLOW VARIABLEYou need to store the query parameter CustID in flow variable. So you can use that flow variable for routing message to correct recipient.

Page 6: What is Content Based Routing With Mulesoft

CHOICE ROUTERPlace 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

Page 7: What is Content Based Routing With Mulesoft

TESTING THE APPLICATIONYou 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'.

Page 8: What is Content Based Routing With Mulesoft

TESTING THE APPLICATIONCase 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'.

Page 9: What is Content Based Routing With Mulesoft

TESTING THE APPLICATIONCase 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'.

Page 10: What is Content Based Routing With Mulesoft

THANK YOU