Shared Subscriptions for Topics
Shared subscriptions allow an application to share the work of receiving messages on a topic among multiple message consumers.
When multiple consumers share a subscription, only one consumer in the group receives each new message. This is similar in function to a queue; however, there are no restrictions placed on the type of consumers to the topic, meaning that a topic can have a mix of shared and not shared, durable and non-durable consumers. When a message is published to the topic, the same message goes to all the matching subscriptions.
Shared subscriptions are created with a specific name, and optionally a client ID. Consumers sharing the subscription specify this name when subscribing to the topic. If the shared subscription type is durable, it persists and continues to accumulate messages until deleted. If the shared subscription type is non-durable, it persists only so long as subscribers exist.
For example, the topic foo might have the following subscriptions:
- not shared, non-durable subscription
- not shared, durable subscription
- shared, non-durable subscription called mySharedSub with three shared consumers
- shared, durable subscription called myDurableSharedSub with two shared consumers
If a message is received on foo, each of the above four subscriptions receive that same message. For the shared subscriptions mySharedSub and myDurableSharedSub, the message is delivered to only one if its respective shared consumers.
If the shared consumers of the shared durable subscription myDurableSharedSub are closed, then the shared durable subscription continues to exist and accumulate messages until it is deleted, or until the application creates a new durable shared consumer named myDurableSharedSub to resume this subscription. If the shared consumers of mySharedSub are all closed, the subscription is removed from topic foo.
See Create a Message Consumer for details on how to create shared subscriptions.