Storage in Queue & Topic
Messages for Queues and Topics are stored slightly differently, and match delivery semantics for the point-to-point and publish/subscribe message domains. Storage of Queues are straightforward, they are basically stored in first in, first out order (FIFO) - see Figure 4.1, with only one message being dispatched between one of potentially many consumers. When that message has been consumed, it can be deleted from the store.
For durable subscribers on a Topic, each consumer gets a copy of the message - but in order to save space (some messages can be very large!) messages are in fact only stored once. A durable subscriber object in the store maintains a pointer to its next stored message - and dispatches a copy of it to its consumer - as shown in Figure 4.2. A message store is implemented in this way for durable subscribers because durable subscribers will be consuming messages at different rates; and may not be active at the same time. In addition, as every message can potentially have many consumers, a message cannot be deleted from the store until it has been delivered to every interested consumer.
NMS Code in Queue & Topic
- Topic or Queue Publisher
- Topic or Queue Subscriber
Result:
Queue:
Topic: