Class AmqpMessageListenerContainer
java.lang.Object
org.springframework.amqp.client.listener.AmqpMessageListenerContainer
- All Implemented Interfaces:
MessageListenerContainer, Aware, BeanNameAware, InitializingBean, Lifecycle, Phased, SmartLifecycle
public class AmqpMessageListenerContainer
extends Object
implements MessageListenerContainer, BeanNameAware
The
MessageListenerContainer implementation for AMQP 1.0 protocol.
When autoAccept is false,
an MessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment)
is populated to the Spring AMQP message to be handled by the listener.
Therefore, the listener must manually acknowledge the message or reject/requeue, according to its logic.
If a ProtonDeliveryListener is provided and autoAccept == false,
it is the listener's responsibility to acknowledge the message manually and replenish the link credits.
- Since:
- 4.1
- Author:
- Artem Bilan
-
Field Summary
Fields inherited from interface SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThe 'id' attribute of the listener.@Nullable ObjectGet the message listener.booleanbooleanvoidpause()Pause all the consumers for all queues.voidPause all the consumers for the specific queue.voidresume()Resume all the consumers for all queues.voidResume all the consumers for the specific queue.voidsetAdviceChain(Advice... advices) Set an advice chain to apply to the listener.voidsetAutoAccept(boolean autoAccept) Set tofalseto propagate aMessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment)for targetMessageListenermanual acknowledgement.voidsetAutoStartup(boolean autoStart) Set auto startup.voidsetBeanName(String name) voidsetConsumersPerQueue(int consumersPerQueue) Each queue runs in its own consumer; set this property to create multiple consumers for each queue.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 of credits to grant to the AMQP receiver.voidsetListenerId(String id) Set the listener id.voidsetQueueNames(String... queues) Set the queue names or AMQP 1.0 addresses.voidsetReceiveTimeout(Duration receiveTimeout) Set the timeout for deliveries from the broker in theAmqpMessageListenerContainer.AmqpConsumer.voidsetRecoveryBackOff(BackOff recoveryBackOff) Specify theBackOfffor a failed consumer recovery.voidsetRecoveryInterval(Duration recoveryInterval) Set an interval between recovery attempts of a failed consumer.voidsetTaskExecutor(Executor taskExecutor) Set a task executor to run consumers.voidsetupMessageListener(MessageListener messageListener) Set up the message listener to use.voidstart()voidstop()voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageListenerContainer
isConsumerBatchEnabled, lazyLoadMethods inherited from interface SmartLifecycle
getPhase, isPauseable
-
Constructor Details
-
AmqpMessageListenerContainer
-
-
Method Details
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
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.
-
setQueueNames
Description copied from interface:MessageListenerContainerSet the queue names or AMQP 1.0 addresses.- Specified by:
setQueueNamesin interfaceMessageListenerContainer- Parameters:
queues- the queue names.
-
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).
-
setAutoAccept
public void setAutoAccept(boolean autoAccept) Set tofalseto propagate aMessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment)for targetMessageListenermanual acknowledgement.- Parameters:
autoAccept- to callDelivery.accept()automatically by the ProtonJ Client.
-
setInitialCredits
public void setInitialCredits(int initialCredits) The initial number of credits to grant to the AMQP receiver. The default is100.- Parameters:
initialCredits- number of initial credits- See Also:
-
setAdviceChain
Set an advice chain to apply to the listener.- Parameters:
advices- the advice chain.
-
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
-
setTaskExecutor
Set a task executor to run consumers.- Parameters:
taskExecutor- the task executor.
-
setReceiveTimeout
Set the timeout for deliveries from the broker in theAmqpMessageListenerContainer.AmqpConsumer. Default 1 second.- Parameters:
receiveTimeout- the timeout waiting for deliveries in the consumer.
-
setRecoveryInterval
Set an interval between recovery attempts of a failed consumer. Default 5 seconds.- Parameters:
recoveryInterval- the interval between recovery attempts.- Since:
- 4.1.1
- See Also:
-
setRecoveryBackOff
Specify theBackOfffor a failed consumer recovery. The receiver link is not restored by the ProtonJ client itself, even when the connection is re-established, so the consumer re-opens its receiver according to thisBackOff. The consumer is stopped when theBackOffreturnsBackOffExecution.STOP, and then theisRunning()returnsfalseas soon as no consumers are left in this container. The default isFixedBackOffwith a 5-second interval and unlimited attempts.- Parameters:
recoveryBackOff- theBackOffto use for the consumer recovery.- Since:
- 4.1.1
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean- Specified by:
afterPropertiesSetin interfaceMessageListenerContainer
-
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
-
start
-
stop
-
stop
- Specified by:
stopin interfaceSmartLifecycle
-
isRunning
-
pause
public void pause()Pause all the consumers for all queues. -
resume
public void resume()Resume all the consumers for all queues. -
pause
Pause all the consumers for the specific queue.- Parameters:
queueName- the queue to pause consumers.
-
resume
Resume all the consumers for the specific queue.- Parameters:
queueName- the queue to resume consumers.
-