Mule Studio offers easy-to-use components to connect to JMS 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 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>.
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.
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.
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.
Click on the References tab and select “Active_MQ” for Connection Reference. We created the “Active_MQ” connector in Step 2.
Click OK to save these properties and return to JMS Message Flow.
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/.
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.
More details on ActiveMQ integration can be found in the Mule 3 User Guide.