Class AmqpMessageListenerContainer
java.lang.Object
org.springframework.amqp.client.listener.AmqpMessageListenerContainer
- All Implemented Interfaces:
org.springframework.amqp.core.MessageListenerContainer, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
public class AmqpMessageListenerContainer
extends Object
implements org.springframework.amqp.core.MessageListenerContainer, org.springframework.beans.factory.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
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThe 'id' attribute of the listener.@Nullable Objectbooleanbooleanvoidpause()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(org.aopalliance.aop.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) voidsetBeanName(String name) voidsetConsumersPerQueue(int consumersPerQueue) Each queue runs in its own consumer; set this property to create multiple consumers for each queue.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 of credits to grant to the AMQP receiver.voidsetListenerId(String id) voidsetQueueNames(String... queues) voidsetReceiveTimeout(Duration receiveTimeout) Set the timeout for deliveries from the broker in theAmqpMessageListenerContainer.AmqpConsumer.voidsetRecoveryBackOff(org.springframework.util.backoff.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(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.core.MessageListenerContainer
isConsumerBatchEnabled, lazyLoadMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isPauseable
-
Constructor Details
-
AmqpMessageListenerContainer
-
-
Method Details
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setupMessageListener
public void setupMessageListener(org.springframework.amqp.core.MessageListener messageListener) - Specified by:
setupMessageListenerin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
getMessageListener
- Specified by:
getMessageListenerin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
setQueueNames
- Specified by:
setQueueNamesin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
setListenerId
- Specified by:
setListenerIdin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
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
public void setAdviceChain(org.aopalliance.aop.Advice... advices) 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
public void setErrorHandler(org.springframework.util.ErrorHandler errorHandler) -
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
public void setRecoveryBackOff(org.springframework.util.backoff.BackOff recoveryBackOff) 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 interfaceorg.springframework.beans.factory.InitializingBean- Specified by:
afterPropertiesSetin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
setAutoStartup
public void setAutoStartup(boolean autoStart) - Specified by:
setAutoStartupin interfaceorg.springframework.amqp.core.MessageListenerContainer
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
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
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
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.
-