Content based router using Mule ESB – EIP Series


EIP Series 1.1: Content Based Router using Mule ESB

Let’s start the EIP series with Mule ESB. As mentioned we are going to, implement a simple use case using ‘Content based router’.

Creating mule flow is always interesting because of Mule Studio. Everything is configurable using UI :)

Use case:

Let’s take a retail use case here. When a bunch of stocks arrive at the retail store, the retailer has to segregate based on the product categories. The store will have separate database for every category. Let’s take four categories: Books, Toys, Clothes & Mobiles. For every message coming in, the retailer has to forward the message based on its category. Each message will have a category description.

Let’s use the ‘Content based router (CBR)’ in place of the retailer.


  1. Create one inbound endpoint and four outbound endpoints for each category. Grab the content based router from the flow control window located at the right side of the Mule flow and drop it between the inbound and outbound endpoints. Name and configure all the endpoints. (Here we will take JMS Queues as our inbound and outbound endpoints, MuleConfig XML is given below)
  2. Configure the Content based router using XPath for fixing up filtering values. By double clicking it you will be getting this configuration UI.

Content Based Router Figure 1: Content Based Router – Mule Studio configuration


3. The complete flow should look similar to this.

Mule flow - Content based router

Figure 2: Mule flow – Content based router

4. The mule flow editor has the source view option where you can see the XML configuration of the flow. Refer the following code after you create the flow, even you can test flow by directly copying this code.

 <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file=""





xsi:schemaLocation=" ">


brokerURL="tcp://localhost:61616"validateConnections="true"doc:name="Active MQ"/>











































Send the input message provided below to the Input queue. (As per the given Mule configuration)

You can use the ActiveMQ web console to send and monitor messages here http://localhost:8161/admin

Figure 3: Queue monitor – Message being sent to ‘Books’ queue. Figure 3: Queue monitor – Message being sent to ‘Books’ queue


The input message contains book information; you can notice that the message is being sent to ‘Books’ queue. This is because the category is set to ‘Books’, try changing the category to Toys or Clothes or Mobiles. You should be able to notice that the messages are being sent its respective queues.

Input XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- BusHorn - CBR using Mule ESB - EIP Series 1.1 -->
<name>Life of PI</name>


Hope CBR routes your messages to the proper destination.

Happy Integration !

Gnanaguru Sattanathan

Gnanaguru Sattanathan

I am a Integration developer and a open source enthusiast. My areas of interest includes Enterprise messaging & SOA. Twitter: @tallguru

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>