112 WCTME: Application Development and Case Study
Queues
A queue is where messages are stored before they are sent to their destination,
and after they have arrived there. A program can define its own queues or use
the standard queues provided by MQe.
A queue can be local or remote. A
local queue resides on the same system as
the program sending messages to it. It could be used, for example, to send
messages between programs running on the same computer. A
remote queue
exists on another computer, but MQe stores messages locally before forwarding
them to their destinations.
A remote queue can be synchronous or asynchronous. A
synchronous queue
requires a connection to the actual queue. An
asynchronous queue allows
messages to be sent even if there is no active connection. Messages are stored
until they are delivered.
Queue managers
Queue managers manage the queues and take care of details of sending and
receiving messages. Your program interacts with the queue manager, rather than
the queues.
In MQe, there can only be one queue manager for each JVM.
Connections
A connection acts as a pipe between queue managers, allowing messages to
flow between computers. A connection identifies the target queue manager, the
IP address and the port number of the listener for the queue manager.
Before you can define a remote queue, you must define a connection to the
remote queue manager. The connection does not have to be active. You do not
have to have a link to the other queue manager, but you must define the
connection.
Listeners
In order for a queue manager to receive messages from another, remote queue
manager, it must have defined a listener. A
listener identifies the port number
where the system will listen for incoming messages. The port number of the
listener must match the port number of any connections to that queue manager.
5.1.3 Message flow in MQe
In order to see how these pieces fit together, we can look at a simple scenario
(Figure 5-1 on page 113) where program A, running on a computer identified as
Client, with an IP address of 192.168.0.100, wants to send a message to
Chapter 5. Messaging 113
program B, which is running on a computer identified as Server, with an IP
address of 192.168.0.1.
The queue manager on Server is QM1. The queue on QM1 is Q1.
Figure 5-1 Simple Message Flow in MQe
Program A begins by defining a connection to QM1. It knows that QM1 is on
192.168.0.1, and will be listening on port 8082. Next, program A defines Q1 as a
remote queue on QM1.
Meanwhile, program B defines Q1 on QM1. On QM1, Q1 is a local queue. On
QM2, it is a remote queue. Program B then defines a listener for QM1, listening
on port 8082. Finally, it defines a message listener for Q1. The message listener
is a Java interface with a method, messageArrived() which will be called
whenever a message arrives on Q1.
Program A builds a message, puts data into it, and calls QM2 to send the
message to Q1. If there is no connection between the systems, MQe stores the
message in the remote queue on the client. The message will be sent later when
a connection exists.
When the message arrives on QM1, MQe calls the message listener. Program B
can then receive the message and process it.
Note that if program B wants to send a reply back to program A, it would have to
know the queue manager and queue name. It would also have to have
connection to QM2, and QM2 would have to be a listener. So, program B would
also have to know the IP address and port number for the listener. In other
words, the program running on the client would have to set up an MQe server.
Server
QM1
Q1
Client 192.168.0.100
Server 192.168.0.1
Listener
Port:8082
Message
Listener
QM2
QM1/Q1
Connection
QM1
192.168.0.1
Port:8082
Program A

Get IBM Workplace Client Technology Micro Edition Version 5.7.1: Application Development and Case Study now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.