Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

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

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. 

Assumptions

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 MMC Walkthrough.

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.

Prerequisites

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.

  1. Create the example application in Mule Studio. Do not run the application.

  2. Add your WebSphere MQ client libraries to the project build path.

  3. Make sure your WebSphere MQ installation has queues named "in" and "out."

  4. 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).

  5. Edit the following properties in wmq.properties (located at src/main/resources) with the values appropriate for your WebSphere MQ installation:

    
           
                    
                 
    1
    2
    3
    4
    5
    
    wmq.host=
    wmq.port=
    wmq.queue.manager=
    wmq.username=
    wmq.password=
  6. After configuring WMQ, restart the application.

  1. Copy your WebSphere MQ client JARs to your $MULE_HOME/lib/user directory.

    <MULE_HOME> is the root directory of your Mule installation, for example /opt/Mule/mule-standalone-3.3.1.
  2. Ensure that your WebSphere MQ installation has queues named "in" and "out."

  3. Copy the example’s zip file, for example, <MULE_HOME>/examples/wmq/mule-example-wmq-3.3.1.zip, to the $MULE_HOME/apps directory.

  4. 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:

      
                
                         
                      
      1
      
      &lt;MULE_HOME&gt;/bin/mule start

      On a Windows system, go to the <MULE_HOME>\bin by running the following command:

      
                
                         
                      
      1
      
      cd &lt;MULE_HOME&gt;\bin
  5. Edit the following properties in the file <`MULE_HOME>/apps/mule-example-wmq/classes/wmq.properties` with the values appropriate for your Websphere MQ installation:

    
           
                    
                 
    1
    2
    3
    4
    5
    
    wmq.host=
    wmq.port=
    wmq.queue.manager=
    wmq.username=
    wmq.password=
  6. 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 <MULE_HOME>/apps/mule-example-bookstore-3.3.1/mule-config.xml.

To update the timestamps, run the following command:


         
                  
               
1
touch &lt;MULE_HOME&gt;/apps/mule-example-wmq-3.3.1/mule-config.xml

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.

  1. After Mule starts up, open a Web browser and navigate to the following URL:
    http://localhost:8086/services/wmqExample

    WMQ+01

  2. 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".

    WMQ+03

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

    WMQ+04

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

    WMQ+05

How it works

Global Elements

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:

global_WMQ_connector


    
             
          
1
2
3
&lt;wmq:connector name="wmqConnector" hostName="${wmq.host}" port="${wmq.port}" queueManager="${wmq.queue.manager}" username="${wmq.username}" password="${wmq.password}" doc:name="WMQ Connector"&gt;
    &lt;ee:reconnect-forever/&gt;
&lt;/wmq:connector&gt;

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:

global_ajax


    
             
          
1
2
&lt;ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:8086/services/wmqExample"
        resourceBase="${app.home}/docroot" disableReplyTo="true" doc:name="Ajax"/&gt;

Flows

The application contains three flows, which process, then retrieve messages from a WMQ.

Input flow

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.

MessageProcessor Flow

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.

Output Flow

The Output flow reads messages from the " out " queue, then publishes via the AJAX outbound endpoint.

wmqFlows


    
              
           
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
 
 
 
 
&lt;mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio" xmlns:test="http://www.mulesoft.org/schema/mule/test" xmlns:json="http://www.mulesoft.org/schema/mule/json" version="EE-3.4.0" xsi:schemaLocation="
 
http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd
 
http://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd
 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
 
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
 
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd
 
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd "&gt;
 
    &lt;spring:beans&gt;
 
        &lt;spring:bean id="property-placeholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
 
            &lt;spring:property name="location" value="classpath:wmq.properties"/&gt;
 
        &lt;/spring:bean&gt;
 
    &lt;/spring:beans&gt;
 
    &lt;wmq:connector name="wmqConnector" hostName="${wmq.host}" port="${wmq.port}" queueManager="${wmq.queue.manager}" username="${wmq.username}" password="${wmq.password} " doc:name="WMQ Connector" validateConnections="true"&gt;
 
        &lt;ee:reconnect-forever/&gt;
 
    &lt;/wmq:connector&gt;
 
    &lt;ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:8086/services/wmqExample" resourceBase="${app.home}/docroot" disableReplyTo="true" doc:name="Ajax"/&gt;
 
    &lt;flow name="Input" doc:name="Input"&gt;
 
        &lt;ajax:inbound-endpoint channel="/services/wmqExample/enqueue" doc:name="Ajax"/&gt;
 
        &lt;message-properties-transformer doc:name="Message Properties"&gt;
 
            &lt;delete-message-property key="MULE_REPLYTO"/&gt;
 
        &lt;/message-properties-transformer&gt;
 
        &lt;wmq:outbound-endpoint queue="in" connector-ref="wmqConnector" doc:name="WMQ"/&gt;
 
    &lt;/flow&gt;
 
    &lt;flow name="MessageProcessor" doc:name="MessageProcessor"&gt;
 
        &lt;wmq:inbound-endpoint queue="in" connector-ref="wmqConnector" doc:name="WMQ"&gt;
 
            &lt;wmq:transaction action="ALWAYS_BEGIN"/&gt;
 
        &lt;/wmq:inbound-endpoint&gt;
 
        &lt;test:component appendString=" - processed" logMessageDetails="true" waitTime="15000"&gt;&lt;/test:component&gt;
 
        &lt;wmq:outbound-endpoint queue="out" connector-ref="wmqConnector" doc:name="WMQ"&gt;
 
            &lt;wmq:transaction action="ALWAYS_JOIN"/&gt;
 
        &lt;/wmq:outbound-endpoint&gt;
 
    &lt;/flow&gt;
 
    &lt;flow name="Output" doc:name="Output"&gt;
 
        &lt;wmq:inbound-endpoint queue="out" connector-ref="wmqConnector" doc:name="WMQ"/&gt;
 
        &lt;ajax:outbound-endpoint channel="/services/wmqExample/dequeue" cacheMessages="true" doc:name="Ajax"/&gt;
 
    &lt;/flow&gt;
 
&lt;/mule&gt;

See Also