The set of sample files appended to this topic give you a quick
start at connecting WebSphere MQ Everyplace to a WebSphere
Business Integration Event Broker broker.
They enable you to:
- Create two WebSphere MQ Everyplace queue managers: a
server called ServerQM1 and a client called ClientQM1.
- Create connections between them and create the queues necessary for routing
messages.
- Transmit sample point-to-point or publish/subscribe messages through the
message broker.
You can modify any of the samples provided. You must subsequently
compile the Java source code.
The following steps explain how to run
the example. The directory structures described assume that you are using
Windows. On other platforms, you must change these paths accordingly.
- Set up the CLASSPATH for every system
from which you will run programs that communicate with WebSphere MQ Everyplace within WebSphere
Business Integration Event Broker and with WebSphere MQ Everyplace itself
(standalone). You need to add:
- install_dir\classes\mqimqe.jar;
- install_dir\classes\MQeDevice.jar;
- install_dir\classes\MQeExamples.jar;
- install_dir\classes\MQeGateway.jar;
- install_dir\classes\MQeMQBridge.jar;
On some versions of Windows, there is a limit of 255 characters in
a CLASSPATH setting. To avoid encountering this
restriction, you can assign these to a new environment variable, for example MQEPATH, and add %MQEPATH%; to
your CLASSPATH.
- Copy the example files. Right click each link below and click Select
Target As.... Choose the directory in which you want to store
the files.
- Copy the following .ini files:
- Copy the following Java source files to the same directory:
- Compile the Java source files.
- Create WebSphere MQ Everyplace queue managers
on the WebSphere MQ Everyplace client. The file
name is case sensitive; specify it exactly as shown.
From a command prompt,
type:
java examples.install.CreateQueueManager
In the Configuration File box, browse for and select the ClientQM1.ini file,
which is supplied in directory install_dir\examples\MQe.
Set the directory for the queues to x:\ClientQM1 (where x is
a drive letter of your choice). Click OK.
A WebSphere MQ Everyplace client queue manager is created with
a name ClientQM1, with a registry located at x:\ClientQM1\Registry.
- Create the WebSphere MQ Everyplace server queue
manager within WebSphere
Business Integration Event Broker. The
file name is case sensitive; specify it exactly as shown.
From a command
prompt, type:
java examples.install.CreateQueueManager
In the Configuration File box, browse for and select the ServerQM.ini file,
which is supplied in directory install_dir\examples\MQe.
Set the directory for the queues to x:\ServerQM1.
Click OK.
A WebSphere MQ Everyplace server
queue manager is created with a name ServerQM1, with a registry located
at x:\ServerQM1\Registry.
If you browse
the sample ServerQM1.ini file, you might notice
that the listener is set to listen on port 8081. This setting is ignored
on the creation of the queue manager. Later in the configuration, if you choose
to have the MQeInput node take its settings from a configuration file, this
port number will be used.
If you get an error
on creating the server queue manager with text:
com.ibm.broker.mqimqe.examples.rule.AttributeRule
check that you have correctly referenced
install_dir\classes\mqimqe.jar in
the
CLASSPATH.
- Configure message flows. You can either add WebSphere MQ Everyplace nodes
to existing message flows or create new flows. Switch to the Broker
Application Development perspective.
Add the nodes into the message flow. For point-to-point (non publish/subscribe)
messaging, you must include an MQeInput node and an MQeOutput node. For publish/subscribe
messaging, you must include an MQeInput node and a Publication node.
- Configuring the MQeInput node
- For this example, you must set only the Queue
Name (on the General tab). Each MQeInput
node must have a different queue name. In step 8 below,
the example uses the queue name, MQeInputQ1.
You might also want to make other configuration changes (for example,
setting the level of trace) but this is not necessary to be able to run these
scripts.
- Configuring the MQeOutput node
- Check that the Destination Mode (on
the Advanced tab) is Destination
List. Leave all other fields blank.
- Configuring the Publication node
- No action required.
- Deploy the message flow.
Save the message flow
and check that it has no errors. Add the message flow to a bar file and deploy
that to the broker.
Check that the deploy is successful in the Event
Log. You can expect to see messages BIP4040I and BIP2056I.
- The client queue manager is started when the client starts.
- The server queue manager is only started when an MQeInput node is running
and is deployed in a flow where a WebSphere
Business Integration Event Broker broker
is running.
- Deploying a point-to-point message flow (MQeInput to MQeOutput) also starts
the WebSphere MQ Everyplace server queue manager.
- Set up the WebSphere MQ Everyplace queue managers.
Compile and run the SetupMQeExample1 and SetupMQeExample2 programs
to set up the WebSphere MQ Everyplace queue managers.
- SetupMQeExample1 creates a route so
that the client queue manager can contact the server queue manager.
- SetupMQeExample2 creates a queue on
the server queue manager called Inbox that can be used in
the examples for returning messages.
These programs take the following parameters. SetupMQeExample1 requires
all five parameters, in the sequence shown. SetupMQeExample2 requires
the first two only.
- WebSphere MQ Everyplace queue manager name (ServerQM1 in
this example).
- The path to the WebSphere MQ Everyplace client configuration
file (ClientQM1.ini in this example).
- The IP address of the WebSphere MQ Everyplace server
(1.23.45.678 in this example).
- The port on which the WebSphere MQ Everyplace server
is listening. The port number must match the Port specified
on the Listener tab of the MQeInput node properties
dialog. By default, the port number in the MQeInput node properties is 8081.
- The name of the WebSphere MQ queue manager
hosting the WebSphere
Business Integration Event Broker broker (for example, WBRK_QM).
For example, at a command prompt type: java SetupMQeExample1 ServerQM1 ClientQM1.ini 1.23.45.678 8081 WBRK_QM
- Send messages through the message flows.
- For point-to-point messages, use the program SendMessages.
This sends a message using both the MQeMsgObj class
and the MQeMbMsgObj class.
- For publish/subscribe messages, use the program SendPubSubMessages.
This subscribes, publishes, reads the message, and unsubscribes.
Both these programs take the following five parameters, all of which
must be present in the order shown: - The WebSphere MQ Everyplace queue manager name (ServerQM1 in
this example).
- The path to the WebSphere MQ Everyplace client configuration
file (ClientQM1.ini).
- The name of the WebSphere MQ queue manager
hosting the WebSphere
Business Integration Event Broker broker (for example WBRK_QM).
- The name of the WebSphere MQ bridge queue
receiving the input (the queue you named on the MQInput node Queue
Name property; for example MQeInputQ1).
- The name of the WebSphere MQ Everyplace queue where
you want to receive messages back from the broker. The sample code creates
a queue called Inbox but if you already have a WebSphere MQ Everyplace queue defined, you can specify that
queue.
If this queue does not exist, you receive
the exception:
The message retrieved did not contain all of the expected fields.
If you get this exception but the queue
has been
created, the limit of retrieve attempts has been reached, and no message can
be retrieved.
For example, to send point-to-point messages,
type the following at a command prompt: java SendMessages ServerQM1 ClientQM1.ini WBRK_QM MQeInputQ1 Inbox
If you send a message to the broker that is constructed using
an MQeMsgObject object (when all fields are passed
to the broker) the output is similar to:
Reading message from queue
Message: This is the payload
Own message tag: My own tag with some data
If you send a message to the broker that is constructed using
an MQeMbMsgObject object (when only the fields
compatible within the broker are sent) the output is similar to:
Reading message from queue
Message: This is the payload
For example, to send publish/subscribe messages, type
the following at a command prompt:
java SendPubSubMessages ServerQM1 ClientQM1.ini WBRK_QM MQeInputQ1 Inbox
If messages are sent and received successfully, you should
see output similar to:
Started queue manager: ClientQM1
Subscribing to the topics:
climate
humidity
temperature
Put message to QM/queue: WBRK_QM/MQeInputQ2
Publishing message to topic 'climate'
Reading message from queue
Topic: climate
Message: sunny
un-subscribing from the topics:
climate
humidity
temperature
Put message to QM/queue: WBRK_QM/MQeInputQ2
(where MQeInputQ2 is the name of
the MQeInput node used).
If, after the sample
attempts to put a message to the broker queue manager and the
WebSphere MQ bridge
queue, you see the following
WebSphere MQ Everyplace exception:
java.net.ConnectException: Connection refused
you must check the following:
- The broker is started (mqsistart brokername).
- The port number that you specified when you ran SetupMQeExample1 matches
the port number specified on the Listener tab of the
MQeInput node.
- There is a listener running on that port number (type netstat at
a command prompt to check).
- You have specified a WebSphere MQ Everyplace bridge
queue name. (The deploy appears to succeed even if you have not set this parameter.)