Class ActiveMQTopicSubscriber
- All Implemented Interfaces:
jakarta.jms.MessageConsumer,jakarta.jms.TopicSubscriber,AutoCloseable,ActiveMQDispatcher,StatsCapable,MessageAvailableConsumer
TopicSubscriber object to receive messages
that have been published to a topic. A TopicSubscriber object
is the publish/subscribe form of a message consumer. A
MessageConsumer can be created by using
Session.createConsumer.
A TopicSession allows the creation of multiple
TopicSubscriber objects 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 TopicSubscriber objects 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 NoLocal attribute 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 JMS 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 TopicSubscriber for a
particular durable subscription.
A client can change an existing durable subscription by creating a durable
TopicSubscriber with 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 unsubscribe method is used to delete a durable
subscription. The unsubscribe method can be used at the
Session or TopicSession level. This method
deletes the state being maintained on behalf of the subscriber by its
provider.
Creating a MessageConsumer provides the same features as
creating a TopicSubscriber. To create a durable subscriber,
use of Session.CreateDurableSubscriber is recommended. The
TopicSubscriber is provided to support existing code.
- See Also:
-
Session.createConsumer(jakarta.jms.Destination)Session.createDurableSubscriber(jakarta.jms.Topic, java.lang.String)TopicSessionTopicSession.createSubscriber(jakarta.jms.Topic)TopicSubscriberMessageConsumer
-
Field Summary
Fields inherited from class org.apache.activemq.ActiveMQMessageConsumer
deliveredMessages, info, session, unconsumedMessages -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedActiveMQTopicSubscriber(ActiveMQSession theSession, ConsumerId consumerId, ActiveMQDestination dest, String name, String selector, int prefetch, int maximumPendingMessageCount, boolean noLocalValue, boolean browserValue, boolean asyncDispatch) -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets theNoLocalattribute for this subscriber.jakarta.jms.TopicgetTopic()Gets theTopicassociated with this subscriber.Methods inherited from class org.apache.activemq.ActiveMQMessageConsumer
acknowledge, checkClosed, checkMessageListener, close, commit, dispatch, dispose, getAvailableListener, getConsumerId, getConsumerName, getConsumerStats, getDestination, getFailureError, getLastDeliveredSequenceId, getMessageListener, getMessageSelector, getMessageSize, getOptimizedAckScheduledAckInterval, getPrefetchNumber, getRedeliveryPolicy, getStats, getTransformer, hasMessageListener, isBrowser, isConsumerExpiryCheckEnabled, isDurableSubscriber, isInUse, isNoLocal, iterate, receive, receive, receiveNoWait, rollback, sendPullCommand, setAvailableListener, setConsumerExpiryCheckEnabled, setFailureError, setMessageListener, setOptimizeAcknowledge, setOptimizedAckScheduledAckInterval, setPrefetchSize, setRedeliveryPolicy, setTransformer, start, stop, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jakarta.jms.MessageConsumer
close, getMessageListener, getMessageSelector, receive, receive, receiveNoWait, setMessageListener
-
Constructor Details
-
ActiveMQTopicSubscriber
protected ActiveMQTopicSubscriber(ActiveMQSession theSession, ConsumerId consumerId, ActiveMQDestination dest, String name, String selector, int prefetch, int maximumPendingMessageCount, boolean noLocalValue, boolean browserValue, boolean asyncDispatch) throws jakarta.jms.JMSException - Parameters:
theSession-value-dest-name-selector-cnum-noLocalValue-browserValue-asyncDispatch-- Throws:
jakarta.jms.JMSException
-
-
Method Details
-
getTopic
public jakarta.jms.Topic getTopic() throws jakarta.jms.JMSExceptionGets theTopicassociated with this subscriber.- Specified by:
getTopicin interfacejakarta.jms.TopicSubscriber- Returns:
- this subscriber's
Topic - Throws:
jakarta.jms.JMSException- if the JMS provider fails to get the topic for this topic subscriber due to some internal error.
-
getNoLocal
public boolean getNoLocal() throws jakarta.jms.JMSExceptionGets theNoLocalattribute for this subscriber. The default value for this attribute is false.- Specified by:
getNoLocalin interfacejakarta.jms.TopicSubscriber- Returns:
- true if locally published messages are being inhibited
- Throws:
jakarta.jms.JMSException- if the JMS provider fails to get theNoLocalattribute for this topic subscriber due to some internal error.
-