JMS identifies two styles of messaging (or domains as they’re referred to in the spec)— point-to-point and publish/subscribe. Most Message Oriented MiddleWares (MOM)s already supported both of these messaging styles.
Point to Point Domain
- The point-to-point (PTP) messaging domain uses destinations known as queues.
- Messages are sent and received either synchronously or asynchronously using queues.
- Each message received on the queue is delivered once and only once to a single consumer.
- Consumers receive messages from the queue either synchronously using the MessageConsumer.receive() method or asynchronously by registering a
- MessageListener implementation using the MessageConsumer.setMessage-Listener() method.
- The queue stores all messages until they’re delivered or until they expire.
- Multiple consumers can be registered on a single queue.
- Message sent from a single producer and is delivered to a single consumer, not all consumers.
- JMS provider guarantees the delivery of a message once and only once to the next available registered consumer.
Publish / Subscribe Domain
- The publish/subscribe (pub/sub) messaging domain uses destinations known as topics
- Publishers send messages to the topic and subscribers register to receive messages from the topic
- Any messages sent to the topic are automatically delivered to all subscribers ( This messaging domain is similar to subscribing to a mailing list where all subscribers will receive all messages sent to the mailing list in a one-to-many paradigm)
- Topics don’t hold messages unless explicitly instructed to do so, This can be achieved via the use of a durable subscription.
Using a durable subscription, when a subscriber disconnects from the JMS provider, it’s the responsibility of the JMS provider to store messages for the subscriber. Upon reconnecting, the durable subscriber will receive all unexpired messages from the JMS provider. Durable subscriptions allow for subscriber disconnection without missing any messages.
JMS Domain using Topics
Distinguishing message durability from message persistence
Sounds Simple But Yet difficult to understand, there are some semantic differences between them and each has its specific purpose.
Message durability can only be achieved with the pub/sub domain. When clients connect to a topic, they can do so using a durable or a non-durable subscription.
- It is infinite
- It is registered with topic subscription to tell the JMS provider to preserve the subscription state even the subscriber disconnects
- It will preserve the message until subscriber connects again or until subscriber explicitly unsubscribes from the topic.
Non Durable Subscription
- It is finite
- It is registered with topic subscription to tell the JMS provider to not to preserve the subscription state even the subscriber disconnects.
- If a subscriber disconnects, the JMS Provider won’t hold any messages during the disconnected time-span/period.
Message persistence is independent of the message domain. It is a quality of service that indicates the JMS application’s ability to handle missing messages in the event of a JMS provider failure. This Quality of Service is specified on the message producer’s
setDeliveryMode method using one of the
as an argument