Class DirectReplyToMessageListenerContainer
- java.lang.Object
-
- org.springframework.amqp.rabbit.connection.RabbitAccessor
-
- org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
-
- org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer
-
- org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer
-
- All Implemented Interfaces:
MessageListenerContainer
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,Phased
,SmartLifecycle
public class DirectReplyToMessageListenerContainer extends DirectMessageListenerContainer
Listener container for Direct ReplyTo only listens to the pseudo queueAddress.AMQ_RABBITMQ_REPLY_TO
. Consumers are added on-demand and terminated when idle foridleEventInterval
(default 60 seconds).- Since:
- 2.0
- Author:
- Gary Russell
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirectReplyToMessageListenerContainer.ChannelHolder
Holder for a channel; contains a consumer epoch used to prevent inappropriate release of the consumer after it has been allocated for reuse.-
Nested classes/interfaces inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
AbstractMessageListenerContainer.JavaLangErrorHandler, AbstractMessageListenerContainer.SharedConnectionNotInitializedException, AbstractMessageListenerContainer.WrappedTransactionException
-
-
Field Summary
-
Fields inherited from class org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer
consumers
-
Fields inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
consumersMonitor, DEFAULT_DEBATCHING_ENABLED, DEFAULT_PREFETCH_COUNT, DEFAULT_RECOVERY_INTERVAL, DEFAULT_SHUTDOWN_TIMEOUT
-
Fields inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
logger
-
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
-
Constructor Summary
Constructors Constructor Description DirectReplyToMessageListenerContainer(ConnectionFactory connectionFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addQueueNames(String... queueNames)
Add queue(s) to this container's list of queues.protected void
consumerRemoved(org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.SimpleConsumer consumer)
Called whenever a consumer is removed.protected void
doStart()
Start this container, and notify all invoker tasks.protected int
findIdleConsumer()
When adjusting down, return a consumer that can be canceled.DirectReplyToMessageListenerContainer.ChannelHolder
getChannelHolder()
Get the channel holder associated with a direct reply-to consumer; contains a consumer epoch to prevent inappropriate releases.protected void
processMonitorTask()
Subclasses can override this to take additional actions when the monitor task runs.void
releaseConsumerFor(DirectReplyToMessageListenerContainer.ChannelHolder channelHolder, boolean cancelConsumer, String message)
Release the consumer associated with the channel for reuse.boolean
removeQueueNames(String... queueNames)
Remove queue(s) from this container's list of queues.void
setConsumersPerQueue(int consumersPerQueue)
Each queue runs in its own consumer; set this property to create multiple consumers for each queue.void
setMessageListener(MessageListener messageListener)
Set theMessageListener
.void
setMonitorInterval(long monitorInterval)
Set how often to run a task to check for failed consumers and idle containers.void
setQueueNames(String... queueName)
Set the name of the queue(s) to receive messages from.-
Methods inherited from class org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer
actualStart, addQueues, checkConnect, doInitialize, doRedeclareElementsIfNecessary, doShutdown, doStop, removeQueues, setAckTimeout, setExclusive, setMessagesPerAck, setMissingQueuesFatal, setTaskScheduler
-
Methods inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
actualInvokeListener, addAfterReceivePostProcessors, afterPropertiesSet, causeChainHasImmediateAcknowledgeAmqpException, checkMessageListener, checkMismatchedQueues, configureAdminIfNeeded, debatch, destroy, doInvokeListener, doInvokeListener, doSetPossibleAuthenticationFailureFatal, executeListener, getAcknowledgeMode, getAdviceChain, getAfterReceivePostProcessors, getAmqpAdmin, getApplicationContext, getApplicationEventPublisher, getBatchingStrategy, getBeanName, getConnectionFactory, getConsumeDelay, getConsumerArguments, getConsumerTagStrategy, getExclusiveConsumerExceptionLogger, getFailedDeclarationRetryInterval, getIdleEventInterval, getJavaLangErrorHandler, getLastReceive, getListenerId, getMessageListener, getMessagePropertiesConverter, getPhase, getPrefetchCount, getQueueNames, getQueueNamesAsSet, getQueueNamesToQueues, getRecoveryBackOff, getRoutingConnectionFactory, getRoutingLookupKey, getShutdownTimeout, getTaskExecutor, getTransactionAttribute, getTransactionManager, handleListenerException, initialize, initializeProxy, invokeErrorHandler, invokeListener, isActive, isAlwaysRequeueWithTxManagerRollback, isAsyncReplies, isAutoDeclare, isAutoStartup, isChannelLocallyTransacted, isDeBatchingEnabled, isDefaultRequeueRejected, isExclusive, isExposeListenerChannel, isForceCloseChannel, isGlobalQos, isMismatchedQueuesFatal, isMissingQueuesFatal, isMissingQueuesFatalSet, isNoLocal, isPossibleAuthenticationFailureFatal, isPossibleAuthenticationFailureFatalSet, isRunning, isStatefulRetryFatalWithNullMessageId, lazyLoad, prepareHolderForRollback, publishConsumerFailedEvent, publishIdleContainerEvent, publishMissingQueueEvent, redeclareElementsIfNecessary, removeAfterReceivePostProcessor, setAcknowledgeMode, setAdviceChain, setAfterReceivePostProcessors, setAlwaysRequeueWithTxManagerRollback, setAmqpAdmin, setApplicationContext, setApplicationEventPublisher, setAutoDeclare, setAutoStartup, setBatchingStrategy, setBeanName, setConsumeDelay, setConsumerArguments, setConsumerTagStrategy, setDeBatchingEnabled, setDefaultRequeueRejected, setErrorHandler, setErrorHandlerLoggerName, setExclusiveConsumerExceptionLogger, setExposeListenerChannel, setFailedDeclarationRetryInterval, setForceCloseChannel, setGlobalQos, setIdleEventInterval, setjavaLangErrorHandler, setListenerId, setLookupKeyQualifier, setMessagePropertiesConverter, setMicrometerEnabled, setMicrometerTags, setMismatchedQueuesFatal, setNoLocal, setPhase, setPossibleAuthenticationFailureFatal, setPrefetchCount, setQueues, setRecoveryBackOff, setRecoveryInterval, setShutdownTimeout, setStatefulRetryFatalWithNullMessageId, setTaskExecutor, setTransactionAttribute, setTransactionManager, setupMessageListener, shutdown, start, stop, stop, updateLastReceive, validateConfiguration, wrapToListenerExecutionFailedExceptionIfNeeded
-
Methods inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
convertRabbitAccessException, createConnection, getChannel, getConnection, getTransactionalResourceHolder, isChannelTransacted, setChannelTransacted, setConnectionFactory
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
isConsumerBatchEnabled
-
-
-
-
Constructor Detail
-
DirectReplyToMessageListenerContainer
public DirectReplyToMessageListenerContainer(ConnectionFactory connectionFactory)
-
-
Method Detail
-
setConsumersPerQueue
public final void setConsumersPerQueue(int consumersPerQueue)
Description copied from class:DirectMessageListenerContainer
Each queue runs in its own consumer; set this property to create multiple consumers for each queue. If the container is already running, the number of consumers per queue will be adjusted up or down as necessary.- Overrides:
setConsumersPerQueue
in classDirectMessageListenerContainer
- Parameters:
consumersPerQueue
- the consumers per queue.
-
setMonitorInterval
public final void setMonitorInterval(long monitorInterval)
Description copied from class:DirectMessageListenerContainer
Set how often to run a task to check for failed consumers and idle containers.- Overrides:
setMonitorInterval
in classDirectMessageListenerContainer
- Parameters:
monitorInterval
- the interval; default 10000 but it will be adjusted down to the smallest of this,idleEventInterval
/ 2 (if configured) orfailedDeclarationRetryInterval
.
-
setQueueNames
public final void setQueueNames(String... queueName)
Description copied from class:AbstractMessageListenerContainer
Set the name of the queue(s) to receive messages from.- Specified by:
setQueueNames
in interfaceMessageListenerContainer
- Overrides:
setQueueNames
in classDirectMessageListenerContainer
- Parameters:
queueName
- the desired queueName(s) (can not benull
)
-
addQueueNames
public final void addQueueNames(String... queueNames)
Description copied from class:AbstractMessageListenerContainer
Add queue(s) to this container's list of queues.- Overrides:
addQueueNames
in classDirectMessageListenerContainer
- Parameters:
queueNames
- The queue(s) to add.
-
removeQueueNames
public final boolean removeQueueNames(String... queueNames)
Description copied from class:AbstractMessageListenerContainer
Remove queue(s) from this container's list of queues.- Overrides:
removeQueueNames
in classDirectMessageListenerContainer
- Parameters:
queueNames
- The queue(s) to remove.- Returns:
- the boolean result of removal on the target
queueNames
List.
-
setMessageListener
public void setMessageListener(MessageListener messageListener)
Description copied from class:AbstractMessageListenerContainer
Set theMessageListener
.- Overrides:
setMessageListener
in classAbstractMessageListenerContainer
- Parameters:
messageListener
- the listener.
-
doStart
protected void doStart()
Description copied from class:AbstractMessageListenerContainer
Start this container, and notify all invoker tasks.- Overrides:
doStart
in classDirectMessageListenerContainer
-
processMonitorTask
protected void processMonitorTask()
Description copied from class:DirectMessageListenerContainer
Subclasses can override this to take additional actions when the monitor task runs.- Overrides:
processMonitorTask
in classDirectMessageListenerContainer
-
findIdleConsumer
protected int findIdleConsumer()
Description copied from class:DirectMessageListenerContainer
When adjusting down, return a consumer that can be canceled. Called while synchronized on consumersMonitor.- Overrides:
findIdleConsumer
in classDirectMessageListenerContainer
- Returns:
- the consumer index or -1 if non idle.
-
consumerRemoved
protected void consumerRemoved(org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.SimpleConsumer consumer)
Description copied from class:DirectMessageListenerContainer
Called whenever a consumer is removed.- Overrides:
consumerRemoved
in classDirectMessageListenerContainer
- Parameters:
consumer
- the consumer.
-
getChannelHolder
public DirectReplyToMessageListenerContainer.ChannelHolder getChannelHolder()
Get the channel holder associated with a direct reply-to consumer; contains a consumer epoch to prevent inappropriate releases.- Returns:
- the channel holder.
-
releaseConsumerFor
public void releaseConsumerFor(DirectReplyToMessageListenerContainer.ChannelHolder channelHolder, boolean cancelConsumer, @Nullable String message)
Release the consumer associated with the channel for reuse. Set cancelConsumer to true if the client is not prepared to handle/discard a late arriving reply.- Parameters:
channelHolder
- the channel holder.cancelConsumer
- true to cancel the consumer.message
- a message to be included in the cancel event if cancelConsumer is true.
-
-