The following samples demonstrates how Point-to-point messaging differs from Publish and Subscribe messaging.
In the Talk
application, whenever a text message is
sent to a given queue, all active Talk
applications
that are waiting to receive messages on that queue take turns receiving
the message at the front of the queue.
To run the Talking sample do the following:
In window 1, enter ant talk1
.
In window 2, enter ant talk2
.
In window 3, enter ant talk3
.
In the Talker1 window, type
1
, and then press
Enter.
The text is displayed in only one of the other
Q1
receiver windows. A point-to-point
message has only one receiver.
Again, in the Talker1 window, type
2
, and then press
Enter.
The text is displayed in the other Q1
receiver window. Multiple receivers on a queue take turns
receiving messages.
In the Talker1 window, create several
messages, such as 3
,4
, ...,
9
.
![]() | Important |
---|---|
Be sure to press Enter between each message. |
One of the Q1
receivers gets messages
1, 3, 5, 7, 9
while the other gets
2, 4, 6, 8
.
If you opened another Talker_2 or
Talker_3 window, the distribution to
the Q1
receivers would be 1, 4,
7
for the first, 2, 5, 8
for
the next and 3, 6, 9
for the third.
The QueueMonitor moves through a specified set of queues, listing the active messages it finds as it examines each queue. In the examples to this point, the Talk samples left no messages in any queue.
The monitor samples each open GUI windows that provide a scrolling array of its contents. The nature of the two monitors underscores fundamental differences between the Publish and Subscribe messaging model and the Point-to-point messaging model. The differences between MessageMonitor and QueueMonitor are as follows:
What messages are displayed?
MessageMonitor: Delivered.
QueueMonitor: Undelivered.
When does the display update?
MessageMonitor: When a message is published to a subscribed topic, it is added to the displayed list.
QueueMonitor: When you click the Browse Queues button, the list is refreshed.
When does the message go away?
MessageMonitor: When the display is cleared for any reason.
QueueMonitor: When the message is delivered (or when it expires).
What happens when the broker and monitor are restarted?
MessageMonitor: As messages are listed at
the moment they are delivered, there are no messages in the
MessageMonitor
until new
deliveries occur.
QueueMonitor: Listed messages marked
PERSISTENT
are stored in the broker
persistent storage mechanism. They are redisplayed when the
broker and the QueueMonitor restart
and then choose to browse queues.
To run the QueueMonitor sample do the following:
In window 3, enter ant qmonitor
.
The QueueMonitor
’s console window lists the
queues that have been specified for it to browse.
The QueueMonitor Java window opens.
Click
.The messages in the queue at the moment it is browsed are listed. If you are following along carefully, there should be no messages in any queue.
To put messages into a queue do the following:
In window 1 (where Talker1
is still
running), type 1
and then press
Enter.
Repeat step 1 to create a few messages, such as
2
Enter, 3
Enter, 4
Enter.
In the QueueBrowser window, click .
The messages are in the queue. They will continue to be there until a receiver receives them on that queue, or they expire (set to 30 minutes by the sender).
The messages that are waiting on the queue will get delivered to the next receiver that chooses to receive from that queue.
To receive the queued messages do the following:
In window 2, enter ant talk2
.
When the Talker_2 window opens, it shows that it consumes the messages in the queue is sequence.
In the QueueBrowser window, click .
The queues are all empty. As long as you have receivers on the sample queues, no messages will display in the QueueMonitor window.
The SelectorTalk
sample applications are similar
yet consistent with the behavior of the messaging model. The SelectiveTalkers
both send
and receive on Q1
.
The Talkers
do not
specify selection parameters.
To run the SelectorTalk sample do the following:
In window 1, enter ant
filtertalk1
.
In window 2, enter ant
filtertalk2
.
In window 3, enter ant talk2
.
Talker_2
sends to Q2
and
receives on Q1
.
In the SelectiveTalker_1 window, enter some text and then press Enter. Send a few messages in this window.
The messages are displayed in either that window or the Talker_2 window (usually alternately.)
In the SelectiveTalker_2 window, enter some text and then press Enter. Send a few messages in this window.
The messages are displayed in either that window or the Talker_2 window (usually alternately.)
In the Talker_2 window, enter some text and then press Enter.
None of the windows receives the message.
Talker_2 is receiving on
Q2
. The selective talkers are receiving
on Q1
, but they are qualifying their
selection as only messages that have the specified property,
and, at that, set to their preferred value. So the message will
be stored in Q1
even though there are
receivers on Q1
.
In window 3, press
Ctrl+C
to stop Talker_2
.
In window 3, enter ant talk1
.
Talker_1
sends to Q2
and
receives on Q1
. When it starts, it
immediately receives the messages stored on
Q1
(unless they have expired.)
The transaction samples show that the transaction scope is between the client in the JMS session and the broker. When the broker receives commitment, the messages are placed onto queues or topics in the order in which they were buffered as standard messages. The following message delivery is normal:
Pub/Sub Messages — Messages are delivered in the order entered in the transaction yet influenced by the priority setting of these and other messages, the use of additional receiving sessions, and the use of additional or alternate topics. The messages are not delivered as a group.
PTP Messages — The order of
messages in the queue is maintained with adjustments for
priority differences but there is no guarantee that—when
multiple consumers are active on the queue—a
MessageConsumer
will receive one or more
of the MessageProducer
’s transacted
messages.
To run PTP TransactedTalk sample do the following:
In window 1, enter ant xntalk
.
In the console window that opens, type text in the window and press Enter.
Repeat to produce a few messages.
Type COMMIT
in the window and press
Enter.
In window 2, enter ant qmonitor
.
In the QueueBrowser window, click .
The messages are listed.
In window 3, enter ant talk2
.
The window opens with the series of messages in
Q1
from the TransactedTalker
.
In window 1, type some text, and press Enter.
Repeat to produce a few messages.
Type CANCEL
in the window and press
Enter.
The batch of messages is dropped:
In window 3—the talk2 window, no
messages are received on Q1
.
In the QueueBrowser window,
Browse Queues lists no messages
in Q1
.
In window 1, do the following:
Type some text.
Press Enter.
Type COMMIT
.
Press Enter.
The newly-committed transaction batch is received in window 3.