Publish/Subscribe Messaging

The JMS pub/sub model defines how JMS clients publish messages to and subscribe to messages from a well known topics. Unlike in the PTP model, the messages produced by a publisher may be subscribed and consumed by multiple consumers. Examples include:

Messages are published to topics by one or more topic publishers. Interested users subscribe to one or more topics in order to receive those messages. A topic does not retain messages in the same way as a queue, so if a topic has no subscribers incoming message will be thrown away. A subscriber will only get messages that were sent to the topic after the subscription was made.

A subscription to a topic can be made either durable or non-durable. A durable subscription allows subscribers to be inactive at times. When a subscriber re-connects (opens an existing subscription), messages received by the topic during the inactive period will be delivered to the subscriber. This allows topic subscribers to take advantage of persistent messages.

The pub/sub examples included in this tutorial are listed below:

Hello World

This sample program demonstrates the use of the JMS Pub/Sub model using a topic publisher and a topic subscriber.

Durable Subscribers

Unless topic subscriber is durable, it only receives messages published to the topic when it is active. Each durable subscriber has a unique name and clientId, and only one session at a time can have a subscriber for a given durable subscription. This sample program shows how to create and delete a durable subscription, as well as receiving messages.


Copyright © 1998-2003, Novell, Inc. All rights reserved.