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

    • AmqpMessageListenerContainer

      public AmqpMessageListenerContainer(AmqpConnectionFactory connectionFactory)
  • Method Details

    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • setupMessageListener

      public void setupMessageListener(org.springframework.amqp.core.MessageListener messageListener)
      Specified by:
      setupMessageListener in interface org.springframework.amqp.core.MessageListenerContainer
    • getMessageListener

      public @Nullable Object getMessageListener()
      Specified by:
      getMessageListener in interface org.springframework.amqp.core.MessageListenerContainer
    • setQueueNames

      public void setQueueNames(String... queues)
      Specified by:
      setQueueNames in interface org.springframework.amqp.core.MessageListenerContainer
    • setListenerId

      public void setListenerId(String id)
      Specified by:
      setListenerId in interface org.springframework.amqp.core.MessageListenerContainer
    • 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(org.aopalliance.aop.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(org.springframework.util.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.
    • setRecoveryInterval

      public void setRecoveryInterval(Duration recoveryInterval)
      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 the BackOff for 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 this BackOff. The consumer is stopped when the BackOff returns BackOffExecution.STOP, and then the isRunning() returns false as soon as no consumers are left in this container. The default is FixedBackOff with a 5-second interval and unlimited attempts.
      Parameters:
      recoveryBackOff - the BackOff to use for the consumer recovery.
      Since:
      4.1.1
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Specified by:
      afterPropertiesSet in interface org.springframework.amqp.core.MessageListenerContainer
    • setAutoStartup

      public void setAutoStartup(boolean autoStart)
      Specified by:
      setAutoStartup in interface org.springframework.amqp.core.MessageListenerContainer
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.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

      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.