Information Technology Reference
In-Depth Information
Logical Queue
Producer
Consumer
Node 1
Node 2
Figure 2.15.
Message queues.
Space decoupling. The interacting parties do not need to know each other as pub-
lishers publish messages through an event service and subscribers receive
these events indirectly from the event service. Publishers and subscribers
are not aware of each other nor do they hold references to each other.
A number of message queueing systems are widely available, such as MQSeries
from IBM [51], Microsoft's MSMQ [25] and Apache's ActiveMQ [5] and message
queueing is part of the Java Enterprise Edition (JEE) specification [104]inthe
form of message-driven beans and the Java Message Service (JMS) API [47].
Message queueing systems typically provide two different interaction styles,
queues and publish/subscribe.
2.6.1
Message Queues
In the queue interaction style, also referred to as point-to-point , messages are
stored in a FIFO queue. Producers append messages into the queue and consumers
dequeue them at the front of the queue.
Queues typically provide transactional, ordering and timing guarantees and
messages can be one way (fire-and-forget) or two way (request-response) although
a response is not compulsory.
The JMS API [47] provides a simple queuing abstraction for Java applica-
tions. Implementing our simple date application is therefore straightforward. The
server implementation illustrated in Figure 2.16 is developed using Apache's Ac-
tiveMQ [5] messaging product.
In our JMS server example we use the JMS TextMessage type to pass a String
representing the current date from the server to the client. A Properties object
is used to set various connection parameters required by the JMS implementation
and the DateServer classisusedasa MessageListener so that it may receive
messages asynchronously.
The JMS Server example uses a simple messaging request-reply pattern [50]
where the consumer waits for a message to be sent from the producer and, upon
receipt, sends a response back to the producer on a queue defined by the producer
in the JMS reply header field. Once a message is received and if it is of type
TextMessage , the request is printed and a response is sent containing the server's
current date. Our client, illustrated in Figure 2.17, creates a temporary queue for
Search WWH ::




Custom Search