Class DirectReplyToMessageListenerContainer
java.lang.Object
org.springframework.amqp.rabbit.connection.RabbitAccessor
org.springframework.amqp.rabbit.listener.ObservableListenerContainer
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
Listener container for Direct ReplyTo only listens to the pseudo queue
Address.AMQ_RABBITMQ_REPLY_TO
. Consumers are added on-demand and
terminated when idle for idleEventInterval
(default 60 seconds).- Since:
- 2.0
- Author:
- Gary Russell
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
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.DirectMessageListenerContainer
DirectMessageListenerContainer.SimpleConsumer
Nested classes/interfaces inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
AbstractMessageListenerContainer.DefaultExclusiveConsumerLogger, 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
consumersLock, DEFAULT_DEBATCHING_ENABLED, DEFAULT_PREFETCH_COUNT, DEFAULT_RECOVERY_INTERVAL, DEFAULT_SHUTDOWN_TIMEOUT, lifecycleLock, stopNow
Fields inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addQueueNames
(String... queueNames) Add queue(s) to this container's list of queues.protected void
Called whenever a consumer is removed.protected void
doStart()
Start this container, and notify all invoker tasks.protected int
When adjusting down, return a consumer that can be canceled.Get the channel holder associated with a direct reply-to consumer; contains a consumer epoch to prevent inappropriate releases.protected void
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.final boolean
removeQueueNames
(String... queueNames) Remove queue(s) from this container's list of queues.final 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
.final void
setMonitorInterval
(long monitorInterval) Set how often to run a task to check for failed consumers and idle containers.final 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, doStop, removeQueues, setAckTimeout, setExclusive, setMessagesPerAck, setMissingQueuesFatal, setTaskScheduler, shutdownAndWaitOrCallback
Methods inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
actualInvokeListener, addAfterReceivePostProcessors, afterPropertiesSet, causeChainHasImmediateAcknowledgeAmqpException, checkMessageListener, checkMismatchedQueues, configureAdminIfNeeded, debatch, destroy, doInvokeListener, doInvokeListener, doSetPossibleAuthenticationFailureFatal, doShutdown, executeListener, executeListenerAndHandleException, getAcknowledgeMode, getAdviceChain, getAfterReceivePostProcessors, getAmqpAdmin, getApplicationEventPublisher, getBatchingStrategy, getConnectionFactory, getConsumeDelay, getConsumerArguments, getConsumerTagStrategy, getExclusiveConsumerExceptionLogger, getFailedDeclarationRetryInterval, getIdleEventInterval, getJavaLangErrorHandler, getLastReceive, getMessageAckListener, 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, isForceStop, isGlobalQos, isMismatchedQueuesFatal, isMissingQueuesFatal, isMissingQueuesFatalSet, isNoLocal, isPossibleAuthenticationFailureFatal, isPossibleAuthenticationFailureFatalSet, isRunning, isStatefulRetryFatalWithNullMessageId, lazyLoad, prepareHolderForRollback, publishConsumerFailedEvent, publishIdleContainerEvent, publishMissingQueueEvent, redeclareElementsIfNecessary, removeAfterReceivePostProcessor, setAcknowledgeMode, setAdviceChain, setAfterReceivePostProcessors, setAlwaysRequeueWithTxManagerRollback, setAmqpAdmin, setApplicationEventPublisher, setAutoDeclare, setAutoStartup, setBatchingStrategy, setConsumeDelay, setConsumerArguments, setConsumerTagStrategy, setDeBatchingEnabled, setDefaultRequeueRejected, setErrorHandler, setErrorHandlerLoggerName, setExclusiveConsumerExceptionLogger, setExposeListenerChannel, setFailedDeclarationRetryInterval, setForceCloseChannel, setForceStop, setGlobalQos, setIdleEventInterval, setjavaLangErrorHandler, setLookupKeyQualifier, setMessageAckListener, setMessagePropertiesConverter, setMismatchedQueuesFatal, setNoLocal, setNotRunning, setObservationConvention, setPhase, setPossibleAuthenticationFailureFatal, setPrefetchCount, setQueues, setRecoveryBackOff, setRecoveryInterval, setShutdownTimeout, setStatefulRetryFatalWithNullMessageId, setTaskExecutor, setTransactionAttribute, setTransactionManager, setupMessageListener, shutdown, shutdown, start, stop, stop, updateLastReceive, validateConfiguration, wrapToListenerExecutionFailedExceptionIfNeeded
Methods inherited from class org.springframework.amqp.rabbit.listener.ObservableListenerContainer
checkMicrometer, checkObservation, getApplicationContext, getBeanName, getListenerId, getMicrometerHolder, setApplicationContext, setBeanName, setListenerId, setMicrometerEnabled, setMicrometerTags, setObservationEnabled
Methods inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
convertRabbitAccessException, createConnection, getChannel, getConnection, getObservationRegistry, getTransactionalResourceHolder, isChannelTransacted, obtainObservationRegistry, 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 Details
-
DirectReplyToMessageListenerContainer
-
-
Method Details
-
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
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
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
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
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 locked onAbstractMessageListenerContainer.consumersLock
.- Overrides:
findIdleConsumer
in classDirectMessageListenerContainer
- Returns:
- the consumer index or -1 if non-idle.
-
consumerRemoved
Description copied from class:DirectMessageListenerContainer
Called whenever a consumer is removed.- Overrides:
consumerRemoved
in classDirectMessageListenerContainer
- Parameters:
consumer
- the consumer.
-
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.
-