public class ActiveMQMessageConsumer extends Object implements MessageAvailableConsumer, StatsCapable, ActiveMQDispatcher
MessageConsumer
object to receive messages
from a destination. A MessageConsumer
object is created by
passing a Destination
object to a message-consumer creation
method supplied by a session.
MessageConsumer
is the parent interface for all message
consumers.
A message consumer can be created with a message selector. A message selector allows the client to restrict the messages delivered to the message consumer to those that match the selector.
A client may either synchronously receive a message consumer's messages or have the consumer asynchronously deliver them as they arrive.
For synchronous receipt, a client can request the next message from a message
consumer using one of its receive
methods. There are several
variations of receive
that allow a client to poll or wait for
the next message.
For asynchronous delivery, a client can register a
MessageListener
object with a message consumer. As messages
arrive at the message consumer, it delivers them by calling the
MessageListener
's
onMessage
method.
It is a client programming error for a MessageListener
to
throw an exception.
MessageConsumer
,
QueueReceiver
,
TopicSubscriber
,
Session
Modifier and Type | Field and Description |
---|---|
protected LinkedList<MessageDispatch> |
deliveredMessages |
protected ConsumerInfo |
info |
protected ActiveMQSession |
session |
protected MessageDispatchChannel |
unconsumedMessages |
Constructor and Description |
---|
ActiveMQMessageConsumer(ActiveMQSession session,
ConsumerId consumerId,
ActiveMQDestination dest,
String name,
String selector,
int prefetch,
int maximumPendingMessageCount,
boolean noLocal,
boolean browser,
boolean dispatchAsync,
MessageListener messageListener)
Create a MessageConsumer
|
Modifier and Type | Method and Description |
---|---|
void |
acknowledge()
Acknowledge all the messages that have been delivered to the client up to
this point.
|
protected void |
checkClosed() |
protected void |
checkMessageListener() |
void |
close()
Closes the message consumer.
|
void |
commit() |
void |
dispatch(MessageDispatch md) |
void |
dispose() |
MessageAvailableListener |
getAvailableListener()
Gets the listener used to notify synchronous consumers that there is a message
available so that the
MessageConsumer.receiveNoWait() can be called. |
ConsumerId |
getConsumerId() |
String |
getConsumerName() |
JMSConsumerStatsImpl |
getConsumerStats() |
protected ActiveMQDestination |
getDestination() |
IOException |
getFailureError() |
long |
getLastDeliveredSequenceId() |
MessageListener |
getMessageListener()
Gets the message consumer's
MessageListener . |
String |
getMessageSelector()
Gets this message consumer's message selector expression.
|
int |
getMessageSize() |
long |
getOptimizedAckScheduledAckInterval() |
int |
getPrefetchNumber() |
RedeliveryPolicy |
getRedeliveryPolicy() |
StatsImpl |
getStats() |
MessageTransformer |
getTransformer() |
boolean |
hasMessageListener() |
protected boolean |
isBrowser()
Retrieve is a browser
|
boolean |
isConsumerExpiryCheckEnabled() |
boolean |
isDurableSubscriber() |
boolean |
isInUse(ActiveMQTempDestination destination) |
protected boolean |
isNoLocal() |
boolean |
iterate()
Delivers a message to the message listener.
|
Message |
receive()
Receives the next message produced for this message consumer.
|
Message |
receive(long timeout)
Receives the next message that arrives within the specified timeout
interval.
|
Message |
receiveNoWait()
Receives the next message if one is immediately available.
|
void |
rollback() |
protected void |
sendPullCommand(long timeout)
If we have a zero prefetch specified then send a pull command to the
broker to pull a message we are about to receive
|
void |
setAvailableListener(MessageAvailableListener availableListener)
Sets the listener used to notify synchronous consumers that there is a
message available so that the
MessageConsumer.receiveNoWait() can
be called. |
void |
setConsumerExpiryCheckEnabled(boolean consumerExpiryCheckEnabled) |
void |
setFailureError(IOException failureError) |
void |
setMessageListener(MessageListener listener)
Sets the message consumer's
MessageListener . |
protected void |
setOptimizeAcknowledge(boolean value) |
void |
setOptimizedAckScheduledAckInterval(long optimizedAckScheduledAckInterval) |
protected void |
setPrefetchSize(int prefetch) |
void |
setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
Sets the redelivery policy used when messages are redelivered
|
void |
setTransformer(MessageTransformer transformer)
Sets the transformer used to transform messages before they are sent on
to the JMS bus
|
void |
start() |
void |
stop() |
String |
toString() |
protected final ActiveMQSession session
protected final ConsumerInfo info
protected final MessageDispatchChannel unconsumedMessages
protected final LinkedList<MessageDispatch> deliveredMessages
public ActiveMQMessageConsumer(ActiveMQSession session, ConsumerId consumerId, ActiveMQDestination dest, String name, String selector, int prefetch, int maximumPendingMessageCount, boolean noLocal, boolean browser, boolean dispatchAsync, MessageListener messageListener) throws JMSException
session
- dest
- name
- selector
- prefetch
- maximumPendingMessageCount
- noLocal
- browser
- dispatchAsync
- messageListener
- JMSException
public StatsImpl getStats()
getStats
in interface StatsCapable
public JMSConsumerStatsImpl getConsumerStats()
public RedeliveryPolicy getRedeliveryPolicy()
public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
public MessageTransformer getTransformer()
public void setTransformer(MessageTransformer transformer)
public ConsumerId getConsumerId()
public String getConsumerName()
protected boolean isNoLocal()
protected boolean isBrowser()
protected ActiveMQDestination getDestination()
public int getPrefetchNumber()
public boolean isDurableSubscriber()
public String getMessageSelector() throws JMSException
getMessageSelector
in interface MessageConsumer
JMSException
- if the JMS provider fails to receive the next
message due to some internal error.public MessageListener getMessageListener() throws JMSException
MessageListener
.getMessageListener
in interface MessageConsumer
JMSException
- if the JMS provider fails to get the message
listener due to some internal error.MessageConsumer.setMessageListener(javax.jms.MessageListener)
public void setMessageListener(MessageListener listener) throws JMSException
MessageListener
.
Setting the message listener to null is the equivalent of unsetting the message listener for the message consumer.
The effect of calling MessageConsumer.setMessageListener
while messages are being consumed by an existing listener or the consumer
is being used to consume messages synchronously is undefined.
setMessageListener
in interface MessageConsumer
listener
- the listener to which the messages are to be deliveredJMSException
- if the JMS provider fails to receive the next
message due to some internal error.MessageConsumer.getMessageListener()
public MessageAvailableListener getAvailableListener()
MessageAvailableConsumer
MessageConsumer.receiveNoWait()
can be called.getAvailableListener
in interface MessageAvailableConsumer
public void setAvailableListener(MessageAvailableListener availableListener)
MessageConsumer.receiveNoWait()
can
be called.setAvailableListener
in interface MessageAvailableConsumer
public Message receive() throws JMSException
This call blocks indefinitely until a message is produced or until this message consumer is closed.
If this receive
is done within a transaction, the consumer
retains the message until the transaction commits.
receive
in interface MessageConsumer
JMSException
public Message receive(long timeout) throws JMSException
This call blocks until a message arrives, the timeout expires, or this
message consumer is closed. A timeout
of zero never
expires, and the call blocks indefinitely.
receive
in interface MessageConsumer
timeout
- the timeout value (in milliseconds), a time out of zero
never expires.JMSException
public Message receiveNoWait() throws JMSException
receiveNoWait
in interface MessageConsumer
JMSException
- if the JMS provider fails to receive the next
message due to some internal error.public void close() throws JMSException
Since a provider may allocate some resources on behalf of a
MessageConsumer
outside the Java virtual machine, clients should close them when they are
not needed. Relying on garbage collection to eventually reclaim these
resources may not be timely enough.
This call blocks until a receive
or message listener in
progress has completed. A blocked message consumer receive
call returns null when this message consumer is closed.
close
in interface MessageConsumer
JMSException
- if the JMS provider fails to close the consumer due
to some internal error.public void dispose() throws JMSException
JMSException
protected void checkClosed() throws IllegalStateException
IllegalStateException
protected void sendPullCommand(long timeout) throws JMSException
JMSException
protected void checkMessageListener() throws JMSException
JMSException
protected void setOptimizeAcknowledge(boolean value)
protected void setPrefetchSize(int prefetch)
public void acknowledge() throws JMSException
JMSException
public void commit() throws JMSException
JMSException
public void rollback() throws JMSException
JMSException
public void dispatch(MessageDispatch md)
dispatch
in interface ActiveMQDispatcher
public int getMessageSize()
public void start() throws JMSException
JMSException
public void stop()
public boolean iterate()
JMSException
public boolean isInUse(ActiveMQTempDestination destination)
public long getLastDeliveredSequenceId()
public IOException getFailureError()
public void setFailureError(IOException failureError)
public long getOptimizedAckScheduledAckInterval()
public void setOptimizedAckScheduledAckInterval(long optimizedAckScheduledAckInterval) throws JMSException
optimizedAckScheduledAckInterval
- the optimizedAckScheduledAckInterval to setJMSException
public boolean hasMessageListener()
public boolean isConsumerExpiryCheckEnabled()
public void setConsumerExpiryCheckEnabled(boolean consumerExpiryCheckEnabled)
Copyright © 2005–2016 The Apache Software Foundation. All rights reserved.