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,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDirectReplyToMessageListenerContainer.ChannelHolderHolder 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
-
-
Constructor Summary
Constructors Constructor Description DirectReplyToMessageListenerContainer(ConnectionFactory connectionFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddQueueNames(java.lang.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 intfindIdleConsumer()When adjusting down, return a consumer that can be canceled.DirectReplyToMessageListenerContainer.ChannelHoldergetChannelHolder()Get the channel holder associated with a direct reply-to consumer; contains a consumer epoch to prevent inappropriate releases.protected voidprocessMonitorTask()Subclasses can override this to take additional actions when the monitor task runs.voidreleaseConsumerFor(DirectReplyToMessageListenerContainer.ChannelHolder channelHolder, boolean cancelConsumer, java.lang.String message)Release the consumer associated with the channel for reuse.booleanremoveQueueNames(java.lang.String... queueNames)Remove queue(s) from this container's list of queues.voidsetConsumersPerQueue(int consumersPerQueue)Each queue runs in its own consumer; set this property to create multiple consumers for each queue.voidsetMessageListener(org.springframework.amqp.core.MessageListener messageListener)Set theMessageListener.voidsetMonitorInterval(long monitorInterval)Set how often to run a task to check for failed consumers and idle containers.voidsetQueueNames(java.lang.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, setNotRunning, setPhase, setPossibleAuthenticationFailureFatal, setPrefetchCount, setQueues, setRecoveryBackOff, setRecoveryInterval, setShutdownTimeout, setStatefulRetryFatalWithNullMessageId, setTaskExecutor, setTransactionAttribute, setTransactionManager, setupMessageListener, shutdown, start, 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: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
public final void setQueueNames(java.lang.String... queueName)
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
public final void addQueueNames(java.lang.String... queueNames)
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
public final boolean removeQueueNames(java.lang.String... queueNames)
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
public void setMessageListener(org.springframework.amqp.core.MessageListener messageListener)
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
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 java.lang.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.
-
-