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 implementation from Apache that supports 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 http://activemq.apache.org/download.html. 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>.

active-mq

We can see that the ActiveMQ library is now available under Build path.
activemq-libraries

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.

activemq-connector

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.

activemq-http

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.

activemq-jms-1

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

activemq-jms-2

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

activemq-flow_0

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/.

activemq-admin

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.

activemq-seeded

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

No related posts.


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

Anonymous April 28th, 2012, 11:30 am

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 INyyyymmddxxx.zip

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!

Tomek January 30th, 2013, 2:09 am

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.
java.io.IOException: Attempted read from closed stream.
  at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:160)
  at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:184)
  at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
  at org.mule.transformer.simple.ObjectToOutputHandler$3.write(ObjectToOutputHandler.java:76)
  at org.mule.transport.http.HttpServerConnection.writeResponse(HttpServerConnection.java:315)
  at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:164)
  at org.mule.work.WorkerContext.run(WorkerContext.java:311)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown 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.

Venkata April 24th, 2013, 8:00 am

How to subscribe from the ActiveMQ topic using mule esb

Leave a Comment