WebSphere MQ Example
Enterprise Edition, CloudHub
The WebSphere MQ example demonstrates how to use the Websphere MQ Transport to send and receive transactional messages to WebSphere MQ. This example is available in Mule Enterprise Edition.
Cooperate with WMQ
At times, you may find the need to bridge a communication gap between IBM's message queue product, Websphere MQ, and Mule. To facilitate message processing across products, Mule uses a WMQ Endpoint.
This document assumes that you are familiar with Mule ESB. For an overview of basic operations, such as starting the server and locating Mule files, consult the Quick Start Guide to Mule ESB Server and the Management Console.
Set Up and Run the Example
As with this WebSphere MQ example, you can create template applications straight out of the box in Mule Studio or Mule Standalone (Mule ESB without Studio). You can tweak the configurations of these use case-based templates to create your own customized applications in Mule.
Before you run the example, ensure that your system meets the following conditions:
- Mule Enterprise 3.1 or later is installed
- WebSphere MQ 6 or 7 is installed
- the WebSphere MQ client JARs are available to you
Follow one of the two procedures below to create, then run the Websphere MQ application in Mule Studio or Mule Standalone.
- Create the example application in Mule Studio. Do not run the application.
- Add your WebSphere MQ client libraries to the project build path.
- Make sure your WebSphere MQ installation has queues named "in" and "out."
- Run the application. When the application starts, you may see some exceptions in the output console, since WMQ is not configured (we will configure it in the next step).
Edit the following properties in
src/main/resources) with the values appropriate for your WebSphere MQ installation:
- After configuring WMQ, restart the application.
Copy your WebSphere MQ client JARs to your
<MULE_HOME>is the root directory of your Mule installation, for example
- Ensure that your WebSphere MQ installation has queues named "in" and "out."
- Copy the example's zip file, for example,
<MULE_HOME>/examples/wmq/mule-example-wmq-3.3.1.zip, to the
Start Mule, then wait for it to install the example. You may see some exceptions in the logs, since WMQ is not configured yet (we will configure it in the next step).How to start the Mule server
There are several ways to start/stop the Mule server:
- Using the Mule Management Console, which provides a graphical interface for managing servers
- Using the command line
Generally, the simplest way to start the server is by using the command line:
- On a Linux/Unix system, run the following command:
On a Windows system, go to the
<MULE_HOME>\binby running the following command:
Edit the following properties in the file <
MULE_HOME>/apps/mule-example-wmq/classes/wmq.propertieswith the values appropriate for your Websphere MQ installation:
After configuring WMQ, restart Mule or reload the application.How to reload the Websphere MQ app without restarting Mule (Unix)
If you modify the Websphere MQ application while Mule is running, you can reload the application without restarting Mule by "touching" (updating the timestamps of) the file
To update the timestamps, run the following command:
Mule automatically reloads the application, activating any modifications.
In this section we will demonstrate basic usage of the application: sending text messages, then retrieving them from a Websphere MQ using Mule.
- After Mule starts up, open a Web browser and navigate to the following URL:
- The application prompts you to enter text to send a message to WebSphere MQ. The app transmits your input via AJAX/WMQ to the Mule application's "in" queue and you will receive confirmation that your message has been submitted. Enter some text, then hit "Send".
- Mule processes the message sent to the "in" queue, then it sends the confirmation to you via the "out" queue and WMQ/AJAX. Note that Mule introduces an intentional 15 second delay between receiving your message and sending you a confirmation . Mule notifies you when the message is received and its content will be added to the table below.
- Play with it! Start typing several messages in the text box, then hit "Send" to submit them to Mule via AJAX/WMQ. After 15 seconds of intentional delay, the Mule confirms receipt of the messages.
How it works
Mule configures the
WMQ connector with the values previously defined on the
wmq.properties file. In MuleStudio, this configuration is stored as a Global Element, named wmqConnector. To view the configured global element, click the Global Elements tab under the canvas, then double-click the
wmqConnector Global Element. Studio displays the Global Element Properties, shown below:
To be able to send and receive Mule events asynchronously to and from a web browser, we use an AJAX connector. Double-click the connector in the canvas to display its properties:
The application contains three flows, which process, then retrieve messages from a WMQ.
The first building block in the flow is an AJAX Inbound Endpoint, which listens for messages on the configured channel,
/services/wmqExample/enqueue. The flow adds the incoming messages to the "in" queue.
The MessageProcessor flow reads from the "in" queue. The flow's test component appends a string to the message, waits 15 seconds, then adds the message to the 'out' queue.
The Output flow reads messages from the "out" queue, then publishes via the AJAX outbound endpoint.
- Explore more Mule example applications.
- Learn more about the WMQ Endpoint in Mule Studio.
- Learn more about the WMQ transport in Mule.
- Learn more about the AJAX Endpoint in Mule Studio.
- Learn more about the AJAX transport in Mule.