Class RabbitAmqpListenerContainer
java.lang.Object
org.springframework.amqp.rabbitmq.client.listener.RabbitAmqpListenerContainer
- All Implemented Interfaces:
MessageListenerContainer,MessageListenerContainer,Aware,BeanNameAware,DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle
public class RabbitAmqpListenerContainer
extends Object
implements MessageListenerContainer, BeanNameAware, DisposableBean
A listener container for RabbitMQ AMQP 1.0 Consumer.
- Since:
- 4.0
- Author:
- Artem Bilan
-
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 ObjectGet the message listener.booleanbooleanvoidpause()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(Advice... advices) Set an advice chain to apply to the listener.voidsetAfterReceivePostProcessors(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) Set auto startup.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(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) Set the listener id.voidsetPriority(int priority) The consumer priority.voidsetQueueNames(String... queueNames) Set the queue names or AMQP 1.0 addresses.voidsetStateListeners(com.rabbitmq.client.amqp.Resource.StateListener... stateListeners) AddResource.StateListenerinstances to the consumer.voidsetTaskScheduler(TaskScheduler taskScheduler) Set aTaskSchedulerfor monitoring batch releases.voidsetupMessageListener(MessageListener messageListener) Set up the message listener to use.voidstart()voidstop()voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.amqp.core.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
Description copied from interface:MessageListenerContainerSet the queue names or AMQP 1.0 addresses.- Specified by:
setQueueNamesin interfaceMessageListenerContainer- Parameters:
queueNames- the queue names.
-
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
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
Set aTaskSchedulerfor monitoring batch releases.- Parameters:
taskScheduler- theTaskSchedulerto use.
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
setAutoStartup
public void setAutoStartup(boolean autoStart) Description copied from interface:MessageListenerContainerSet auto startup.- Specified by:
setAutoStartupin interfaceMessageListenerContainer- Parameters:
autoStart- true to auto start.
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle
-
setAdviceChain
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
-
setListenerId
Description copied from interface:MessageListenerContainerSet the listener id.- Specified by:
setListenerIdin interfaceMessageListenerContainer- Parameters:
id- the id.
-
getListenerId
The 'id' attribute of the listener.- Returns:
- the id (or the container bean name if no id set).
-
setupMessageListener
Description copied from interface:MessageListenerContainerSet up the message listener to use. Throws anIllegalArgumentExceptionif that message listener type is not supported.- Specified by:
setupMessageListenerin interfaceMessageListenerContainer- Parameters:
messageListener- theobjectto wrapped to theMessageListener.
-
getMessageListener
Description copied from interface:MessageListenerContainerGet the message listener.- Specified by:
getMessageListenerin interfaceMessageListenerContainer- Returns:
- The message listener object.
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean- Specified by:
afterPropertiesSetin interfaceMessageListenerContainer
-
isRunning
-
start
-
stop
-
stop
- Specified by:
stopin interfaceSmartLifecycle
-
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 interfaceDisposableBean
-