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
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
Nested ClassesModifier and TypeClassDescriptionstatic classHolder 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
consumersFields inherited from class org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer
consumersMonitor, DEFAULT_DEBATCHING_ENABLED, DEFAULT_PREFETCH_COUNT, DEFAULT_RECOVERY_INTERVAL, DEFAULT_SHUTDOWN_TIMEOUTFields inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddQueueNames(String... queueNames) Add queue(s) to this container's list of queues.protected voidconsumerRemoved(org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.SimpleConsumer consumer) Called whenever a consumer is removed.protected voiddoStart()Start this container, and notify all invoker tasks.protected intWhen 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 voidSubclasses can override this to take additional actions when the monitor task runs.voidreleaseConsumerFor(DirectReplyToMessageListenerContainer.ChannelHolder channelHolder, boolean cancelConsumer, String message) Release the consumer associated with the channel for reuse.final booleanremoveQueueNames(String... queueNames) Remove queue(s) from this container's list of queues.final voidsetConsumersPerQueue(int consumersPerQueue) Each queue runs in its own consumer; set this property to create multiple consumers for each queue.voidsetMessageListener(MessageListener messageListener) Set theMessageListener.final voidsetMonitorInterval(long monitorInterval) Set how often to run a task to check for failed consumers and idle containers.final voidsetQueueNames(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, setTaskSchedulerMethods 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, setNotRunning, setPhase, setPossibleAuthenticationFailureFatal, setPrefetchCount, setQueues, setRecoveryBackOff, setRecoveryInterval, setShutdownTimeout, setStatefulRetryFatalWithNullMessageId, setTaskExecutor, setTransactionAttribute, setTransactionManager, setupMessageListener, shutdown, start, stop, updateLastReceive, validateConfiguration, wrapToListenerExecutionFailedExceptionIfNeededMethods inherited from class org.springframework.amqp.rabbit.connection.RabbitAccessor
convertRabbitAccessException, createConnection, getChannel, getConnection, getTransactionalResourceHolder, isChannelTransacted, setChannelTransacted, setConnectionFactoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
isConsumerBatchEnabledMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Constructor Details
-
DirectReplyToMessageListenerContainer
-
-
Method Details
-
setConsumersPerQueue
public final void setConsumersPerQueue(int consumersPerQueue) Description copied from class:DirectMessageListenerContainerEach 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:
setConsumersPerQueuein classDirectMessageListenerContainer- Parameters:
consumersPerQueue- the consumers per queue.
-
setMonitorInterval
public final void setMonitorInterval(long monitorInterval) Description copied from class:DirectMessageListenerContainerSet how often to run a task to check for failed consumers and idle containers.- Overrides:
setMonitorIntervalin 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:AbstractMessageListenerContainerSet the name of the queue(s) to receive messages from.- Specified by:
setQueueNamesin interfaceMessageListenerContainer- Overrides:
setQueueNamesin classDirectMessageListenerContainer- Parameters:
queueName- the desired queueName(s) (can not benull)
-
addQueueNames
Description copied from class:AbstractMessageListenerContainerAdd queue(s) to this container's list of queues.- Overrides:
addQueueNamesin classDirectMessageListenerContainer- Parameters:
queueNames- The queue(s) to add.
-
removeQueueNames
Description copied from class:AbstractMessageListenerContainerRemove queue(s) from this container's list of queues.- Overrides:
removeQueueNamesin classDirectMessageListenerContainer- Parameters:
queueNames- The queue(s) to remove.- Returns:
- the boolean result of removal on the target
queueNamesList.
-
setMessageListener
Description copied from class:AbstractMessageListenerContainerSet theMessageListener.- Overrides:
setMessageListenerin classAbstractMessageListenerContainer- Parameters:
messageListener- the listener.
-
doStart
protected void doStart()Description copied from class:AbstractMessageListenerContainerStart this container, and notify all invoker tasks.- Overrides:
doStartin classDirectMessageListenerContainer
-
processMonitorTask
protected void processMonitorTask()Description copied from class:DirectMessageListenerContainerSubclasses can override this to take additional actions when the monitor task runs.- Overrides:
processMonitorTaskin classDirectMessageListenerContainer
-
findIdleConsumer
protected int findIdleConsumer()Description copied from class:DirectMessageListenerContainerWhen adjusting down, return a consumer that can be canceled. Called while synchronized on consumersMonitor.- Overrides:
findIdleConsumerin 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:DirectMessageListenerContainerCalled whenever a consumer is removed.- Overrides:
consumerRemovedin 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.
-