Mule School: Getting started with JMS

Mule Studio offers easy-to-use components to connect to Queues and Topics. In today’s example, we’re going to learn how to use ActiveMQ, a leading open source JMS implementation from Apache that supports JMS 1.1 specification.

Here’s an outline of the simple steps required to implement this example:

  • Import ActiveMQ libraries
  • Create an ActiveMQ connector
  • Enqueue to JMS Queue
  • Run the sample

1. Import ActiveMQ Library

Download ActiveMQ binaries from In this example, I am using the ActiveMQ 5.4.3 release. Unzip the compressed file to any folder on your file system. Let’s call it <ACTIVEMQ_HOME>.

Create a new flow in Mule Studio and name it “jms”. To configure the project to use ActiveMQ libraries, right-click on the project -> Properties -> Java Build Path -> Add External JARs. Select “activemq-all-5.4.3.jar” from <ACTIVEMQ_HOME>.

[singlepic id=42]

We can see that the ActiveMQ library is now available under Build path.
[singlepic id=49 w=580 h=355]

2. Create an ActiveMQ Connector

Double-click on “jms” flow to bring up the message flow. Click on the “Global Elements” tab. Click on “Create” and locate ActiveMQ under “Connectors -> JMS”. Leave the default values for the Active_MQ connector and click OK.

[singlepic id=44 w=580 h=355]

Mule will initialize the ActiveMQ connector with a default instance of the ActiveMQ connection factory and establish a TCP connection to the remote standalone broker running on a local host and listening on port 61616.

3. Enqueue to JMS Queue

We will use the request payload received from an HTTP inbound endpoint to seed the ActiveMQ Queue. Open the “jms” message flow and drag and drop an HTTP endpoint on to the flow.

Double-click on the HTTP endpoint to bring up the properties dialog. Specify “jms” for Path. This will make the HTTP endpoint accessible using URL  http://localhost:8081/jms.

[singlepic id=46 w=580 h=355]

Drag and drop a JMS endpoint next to the HTTP inbound endpoint.

Double-click the JMS endpoint to bring up the properties dialog. Specify “StudioIN” for Queue name. This dialog also allows specifying properties for transactions and exchange patterns. We will explore these concepts in future lessons.

[singlepic id=47 w=580 h=355]

Click on the References tab and select “Active_MQ” for Connection Reference. We created the “Active_MQ” connector in Step 2.

[singlepic id=48 w=580 h=355]

Click OK to save these properties and return to JMS Message Flow.

[singlepic id=52]

We are now ready to run this sample.

4. Run the sample

First, run ActiveMQ using executable “activemq” from <ACTIVEMQ_HOME>/bin folder. Make sure you can access the ActiveMQ admin page using http://localhost:8161/.

[singlepic id=43 w=580 h=355]

In Mule Studio, right-click on “jms” and select “Run as Mule Flow”.

Open http://localhost:8081/jms. This will enqueue the request to the ActiveMQ JMS Queue “StudioIN”.

Verify this by examining the ActiveMQ administration page at http://localhost:8161/admin/queues.jsp. We can see that there is 1 message under the “Messages Enqueued” column.

[singlepic id=50 w=580 h=355]

More details on ActiveMQ integration can be found in the Mule 3 User Guide.

We'd love to hear your opinion on this post

5 Responses to “Mule School: Getting started with JMS”

  1. Thanks a lot! These are very good examples that show how powerful the Mule Flow is and how easy the Mule Studio is to use, well, once you get hang of it.

    I’m learning Mule and I’d like to start from using Mule Studio to create solutions for my work. Can you please give me steps for creating a Mule solution for the following simplified requirement? Even at high level or just give me some directions.

    1. Listen c:\Inbound folder for zip files with file name pattern

    2. Unzip the file to C:\Processing\INyyyymmddxxx folder.

    3. If INyyyymmddxxx.xml is found in the above folder and if the xml file has a “Quote” element, create a txt file INyyyymmddxxx.ack in C:\Response folder. The file will have the Quote in it.

    4. Otherwise create a blank INyyyymmddxxxx.nack file in C:\Response folder.

    5. Write a record to a table in MySql database. The table has three columns: the update timestamp, the incoming zip file name and the response status (ack or nack).

    6. move the initial zip file from C:\Inbound folder to C:\Archive folder.

    Thank you!

  2. If you run the example the way it is presented, you’ll encounter an error:

    ERROR 2013-01-30 11:07:11,371 MY_PACKAGE.connector.http.mule.default.receiver.03] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Attempted read from closed stream. Attempted read from closed stream.
      at org.mule.transformer.simple.ObjectToOutputHandler$3.write(
      at org.mule.transport.http.HttpServerConnection.writeResponse(
      at org.mule.transport.http.HttpMessageReceiver$
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$ Source)
      at Source)

    It is because of req/resp nature of HTTP receiver, just switch it to one-way and it’s done. Or – add some components that in the end return something to that HTTP endpoint.

    Hope this helps somebody.

  3. How to subscribe from the ActiveMQ topic using mule esb

  4. Thank you so much for sharing such a useful post. You have explained all the concepts in detail. I installed mulesoft for the first time today and was able to perform the enqueue operation with your assistance.

  5. nice tutorial