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
  • Constructor Details

    • AmqpMessageListenerContainer

      public AmqpMessageListenerContainer(AmqpConnectionFactory connectionFactory)
  • Method Details

    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface BeanNameAware
    • setupMessageListener

      public void setupMessageListener(MessageListener messageListener)
      Description copied from interface: MessageListenerContainer
      Set up the message listener to use. Throws an IllegalArgumentException if that message listener type is not supported.
      Specified by:
      setupMessageListener in interface MessageListenerContainer
      Parameters:
      messageListener - the object to wrapped to the MessageListener.
    • getMessageListener

      public @Nullable Object getMessageListener()
      Description copied from interface: MessageListenerContainer
      Get the message listener.
      Specified by:
      getMessageListener in interface MessageListenerContainer
      Returns:
      The message listener object.
    • setQueueNames

      public void setQueueNames(String... queues)
      Description copied from interface: MessageListenerContainer
      Set the queue names or AMQP 1.0 addresses.
      Specified by:
      setQueueNames in interface MessageListenerContainer
      Parameters:
      queues - the queue names.
    • setListenerId

      public void setListenerId(String id)
      Description copied from interface: MessageListenerContainer
      Set the listener id.
      Specified by:
      setListenerId in interface MessageListenerContainer
      Parameters:
      id - the id.
    • getListenerId

      public String 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 to false to propagate a MessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment) for target MessageListener manual acknowledgement.
      Parameters:
      autoAccept - to call Delivery.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 is 100.
      Parameters:
      initialCredits - number of initial credits
      See Also:
      • Receiver.addCredit(int)
    • setAdviceChain

      public void setAdviceChain(Advice... advices)
      Set an advice chain to apply to the listener.
      Parameters:
      advices - the advice chain.
    • setGracefulShutdownPeriod

      public void setGracefulShutdownPeriod(Duration gracefulShutdownPeriod)
      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 as concurrency, but per queue.
      Parameters:
      consumersPerQueue - the consumers per queue.
    • setErrorHandler

      public void setErrorHandler(ErrorHandler errorHandler)
    • setTaskExecutor

      public void setTaskExecutor(Executor taskExecutor)
      Set a task executor to run consumers.
      Parameters:
      taskExecutor - the task executor.
    • setReceiveTimeout

      public void setReceiveTimeout(Duration receiveTimeout)
      Set the timeout for deliveries from the broker in the AmqpMessageListenerContainer.AmqpConsumer. Default 1 second.
      Parameters:
      receiveTimeout - the timeout waiting for deliveries in the consumer.
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
      Specified by:
      afterPropertiesSet in interface MessageListenerContainer
    • setAutoStartup

      public void setAutoStartup(boolean autoStart)
      Description copied from interface: MessageListenerContainer
      Set auto startup.
      Specified by:
      setAutoStartup in interface MessageListenerContainer
      Parameters:
      autoStart - true to auto start.
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface Lifecycle
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface SmartLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
    • pause

      public void pause()
      Pause all the consumers for all queues.
    • resume

      public void resume()
      Resume all the consumers for all queues.
    • pause

      public void pause(String queueName)
      Pause all the consumers for the specific queue.
      Parameters:
      queueName - the queue to pause consumers.
    • resume

      public void resume(String queueName)
      Resume all the consumers for the specific queue.
      Parameters:
      queueName - the queue to resume consumers.