Class RabbitAmqpListenerContainer
java.lang.Object
org.springframework.amqp.rabbitmq.client.listener.RabbitAmqpListenerContainer
- All Implemented Interfaces:
org.springframework.amqp.rabbit.listener.MessageListenerContainer, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
public class RabbitAmqpListenerContainer
extends Object
implements org.springframework.amqp.rabbit.listener.MessageListenerContainer, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean
A listener container for RabbitMQ AMQP 1.0 Consumer.
- Since:
- 4.0
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionRabbitAmqpListenerContainer(AmqpConnectionFactory connectionFactory) Construct an instance based on the providedAmqpConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()The 'id' attribute of the listener.@Nullable Objectbooleanbooleanvoidpause()Pause all the consumer for all queues.voidPause all the consumer for specific queue.voidresume()Resume all the consumer for all queues.voidResume all the consumer for specific queue.voidsetAdviceChain(org.aopalliance.aop.Advice... advices) Set an advice chain to apply to the listener.voidsetAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors) SetMessagePostProcessors that will be applied after message reception, before invoking theMessageListener.voidsetAutoSettle(boolean autoSettle) Set tofalseto propagate aMessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment)for targetMessageListenermanual settlement.voidsetAutoStartup(boolean autoStart) voidsetBatchReceiveTimeout(long batchReceiveTimeout) Set a timeout in milliseconds for how long a batch gathering process should go.voidsetBatchSize(int batchSize) Set a number of AMQP messages to gather before producing as a single message downstream.voidsetBeanName(String name) voidsetConsumersPerQueue(int consumersPerQueue) Each queue runs in its own consumer; set this property to create multiple consumers for each queue.voidsetDefaultRequeue(boolean defaultRequeue) Set the default behavior when a message processing has failed.voidsetErrorHandler(org.springframework.util.ErrorHandler errorHandler) voidsetGracefulShutdownPeriod(Duration gracefulShutdownPeriod) Set a duration for how long to wait for all the consumers to shut down successfully on listener container stop.voidsetInitialCredits(int initialCredits) The initial number credits to grant to the AMQP receiver.voidsetListenerId(String id) voidsetPriority(int priority) The consumer priority.voidsetQueueNames(String... queueNames) voidsetStateListeners(com.rabbitmq.client.amqp.Resource.StateListener... stateListeners) AddResource.StateListenerinstances to the consumer.voidsetTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Set aTaskSchedulerfor monitoring batch releases.voidsetupMessageListener(org.springframework.amqp.core.MessageListener messageListener) voidstart()voidstop()voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
isConsumerBatchEnabled, lazyLoadMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isPauseable
-
Constructor Details
-
RabbitAmqpListenerContainer
Construct an instance based on the providedAmqpConnectionFactory.- Parameters:
connectionFactory- to use.
-
-
Method Details
-
setQueueNames
- Specified by:
setQueueNamesin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
setInitialCredits
public void setInitialCredits(int initialCredits) The initial number credits to grant to the AMQP receiver. The default is100.- Parameters:
initialCredits- number of initial credits- See Also:
-
setPriority
public void setPriority(int priority) The consumer priority.- Parameters:
priority- consumer priority- See Also:
-
setStateListeners
public void setStateListeners(com.rabbitmq.client.amqp.Resource.StateListener... stateListeners) AddResource.StateListenerinstances to the consumer.- Parameters:
stateListeners- listeners to add- See Also:
-
setAfterReceivePostProcessors
public void setAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors) SetMessagePostProcessors that will be applied after message reception, before invoking theMessageListener. Often used to decompress data. Processors are invoked in order, depending onPriorityOrder,Orderand finally unordered.- Parameters:
afterReceivePostProcessors- the post processor.
-
setBatchSize
public void setBatchSize(int batchSize) Set a number of AMQP messages to gather before producing as a single message downstream. Default 1 - no batching.- Parameters:
batchSize- the batch size to use.- See Also:
-
setBatchReceiveTimeout
public void setBatchReceiveTimeout(long batchReceiveTimeout) Set a timeout in milliseconds for how long a batch gathering process should go. Therefore, the batch is released as a single message whatever first happens: this timeout orsetBatchSize(int). Default 30 seconds.- Parameters:
batchReceiveTimeout- the timeout for gathering a batch.
-
setTaskScheduler
public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) Set aTaskSchedulerfor monitoring batch releases.- Parameters:
taskScheduler- theTaskSchedulerto use.
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setAutoStartup
public void setAutoStartup(boolean autoStart) - Specified by:
setAutoStartupin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
setAdviceChain
public void setAdviceChain(org.aopalliance.aop.Advice... advices) Set an advice chain to apply to the listener.- Parameters:
advices- the advice chain.
-
setAutoSettle
public void setAutoSettle(boolean autoSettle) Set tofalseto propagate aMessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment)for targetMessageListenermanual settlement. In case ofRabbitAmqpMessageListener, the nativeConsumer.Contextshould be used for manual settlement.- Parameters:
autoSettle- to callConsumer.Context.accept()automatically.
-
setDefaultRequeue
public void setDefaultRequeue(boolean defaultRequeue) Set the default behavior when a message processing has failed. When true, messages will be requeued, when false, they will be discarded. This option can be overruled by throwingAmqpRejectAndDontRequeueExceptionorImmediateRequeueAmqpExceptionfrom the message listener. Default true.- Parameters:
defaultRequeue- true to requeue by default.
-
setGracefulShutdownPeriod
Set a duration for how long to wait for all the consumers to shut down successfully on listener container stop. Default 30 seconds.- Parameters:
gracefulShutdownPeriod- the timeout to wait on stop.
-
setConsumersPerQueue
public void setConsumersPerQueue(int consumersPerQueue) Each queue runs in its own consumer; set this property to create multiple consumers for each queue. Can be treated asconcurrency, but per queue.- Parameters:
consumersPerQueue- the consumers per queue.
-
setErrorHandler
public void setErrorHandler(org.springframework.util.ErrorHandler errorHandler) -
setListenerId
- Specified by:
setListenerIdin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
getListenerId
The 'id' attribute of the listener.- Returns:
- the id (or the container bean name if no id set).
-
setupMessageListener
public void setupMessageListener(org.springframework.amqp.core.MessageListener messageListener) - Specified by:
setupMessageListenerin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
getMessageListener
- Specified by:
getMessageListenerin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Specified by:
afterPropertiesSetin interfaceorg.springframework.amqp.rabbit.listener.MessageListenerContainer
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
pause
public void pause()Pause all the consumer for all queues. -
resume
public void resume()Resume all the consumer for all queues. -
pause
Pause all the consumer for specific queue. -
resume
Resume all the consumer for specific queue. -
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-