Interface TopicSubscriber
-
- All Superinterfaces:
AutoCloseable,MessageConsumer
public interface TopicSubscriber extends MessageConsumer
A client uses aTopicSubscriberobject to receive messages that have been published to a topic. ATopicSubscriberobject is the publish/subscribe form of a message consumer. AMessageConsumercan be created by usingSession.createConsumer.A
TopicSessionallows the creation of multipleTopicSubscriberobjects per topic. It will deliver each message for a topic to each subscriber eligible to receive it. Each copy of the message is treated as a completely separate message. Work done on one copy has no effect on the others; acknowledging one does not acknowledge the others; one message may be delivered immediately, while another waits for its subscriber to process messages ahead of it.Regular
TopicSubscriberobjects are not durable. They receive only messages that are published while they are active.Messages filtered out by a subscriber's message selector will never be delivered to the subscriber. From the subscriber's perspective, they do not exist.
In some cases, a connection may both publish and subscribe to a topic. The subscriber
NoLocalattribute allows a subscriber to inhibit the delivery of messages published by its own connection.If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable
TopicSubscriber. The Jakarta Messaging provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name that uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a
TopicSubscriberfor a particular durable subscription.A client can change an existing durable subscription by creating a durable
TopicSubscriberwith the same name and a new topic and/or message selector. Changing a durable subscription is equivalent to unsubscribing (deleting) the old one and creating a new one.The
unsubscribemethod is used to delete a durable subscription. Theunsubscribemethod can be used at theSessionorTopicSessionlevel. This method deletes the state being maintained on behalf of the subscriber by its provider.Creating a
MessageConsumerprovides the same features as creating aTopicSubscriber. To create a durable subscriber, use ofSession.CreateDurableSubscriberis recommended. TheTopicSubscriberis provided to support existing code.- Since:
- JMS 1.0
- Version:
- Jakarta Messaging 2.0
- See Also:
Session.createConsumer(jakarta.jms.Destination),Session.createDurableSubscriber(jakarta.jms.Topic, java.lang.String),TopicSession,TopicSession.createSubscriber(jakarta.jms.Topic),MessageConsumer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleangetNoLocal()Gets theNoLocalattribute for this subscriber.TopicgetTopic()Gets theTopicassociated with this subscriber.-
Methods inherited from interface jakarta.jms.MessageConsumer
close, getMessageListener, getMessageSelector, receive, receive, receiveNoWait, setMessageListener
-
-
-
-
Method Detail
-
getTopic
Topic getTopic() throws JMSException
Gets theTopicassociated with this subscriber.- Returns:
- this subscriber's
Topic - Throws:
JMSException- if the Jakarta Messaging provider fails to get the topic for this topic subscriber due to some internal error.
-
getNoLocal
boolean getNoLocal() throws JMSExceptionGets theNoLocalattribute for this subscriber. The default value for this attribute is false.- Returns:
- true if locally published messages are being inhibited
- Throws:
JMSException- if the Jakarta Messaging provider fails to get theNoLocalattribute for this topic subscriber due to some internal error.
-
-