Class RabbitAmqpListenerContainer

java.lang.Object
org.springframework.amqp.rabbitmq.client.listener.RabbitAmqpListenerContainer
All Implemented Interfaces:
org.springframework.amqp.rabbit.listener.MessageListenerContainer, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class RabbitAmqpListenerContainer extends Object implements org.springframework.amqp.rabbit.listener.MessageListenerContainer, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean
A listener container for RabbitMQ AMQP 1.0 Consumer.
Since:
4.0
  • Field Summary

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an instance based on the provided AmqpConnectionFactory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    The 'id' attribute of the listener.
    @Nullable Object
     
    boolean
     
    boolean
     
    void
    Pause all the consumer for all queues.
    void
    pause(String queueName)
    Pause all the consumer for specific queue.
    void
    Resume all the consumer for all queues.
    void
    resume(String queueName)
    Resume all the consumer for specific queue.
    void
    setAdviceChain(org.aopalliance.aop.Advice... advices)
    Set an advice chain to apply to the listener.
    void
    setAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)
    Set MessagePostProcessors that will be applied after message reception, before invoking the MessageListener.
    void
    setAutoSettle(boolean autoSettle)
    Set to false to propagate a MessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment) for target MessageListener manual settlement.
    void
    setAutoStartup(boolean autoStart)
     
    void
    setBatchReceiveTimeout(long batchReceiveTimeout)
    Set a timeout in milliseconds for how long a batch gathering process should go.
    void
    setBatchSize(int batchSize)
    Set a number of AMQP messages to gather before producing as a single message downstream.
    void
     
    void
    setConsumersPerQueue(int consumersPerQueue)
    Each queue runs in its own consumer; set this property to create multiple consumers for each queue.
    void
    setDefaultRequeue(boolean defaultRequeue)
    Set the default behavior when a message processing has failed.
    void
    setErrorHandler(org.springframework.util.ErrorHandler errorHandler)
     
    void
    setGracefulShutdownPeriod(Duration gracefulShutdownPeriod)
    Set a duration for how long to wait for all the consumers to shut down successfully on listener container stop.
    void
    setInitialCredits(int initialCredits)
    The initial number credits to grant to the AMQP receiver.
    void
     
    void
    setPriority(int priority)
    The consumer priority.
    void
    setQueueNames(String... queueNames)
     
    void
    setStateListeners(com.rabbitmq.client.amqp.Resource.StateListener... stateListeners)
    Add Resource.StateListener instances to the consumer.
    void
    setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
    Set a TaskScheduler for monitoring batch releases.
    void
    setupMessageListener(org.springframework.amqp.core.MessageListener messageListener)
     
    void
     
    void
     
    void
    stop(Runnable callback)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.amqp.rabbit.listener.MessageListenerContainer

    isConsumerBatchEnabled, lazyLoad

    Methods inherited from interface org.springframework.context.SmartLifecycle

    getPhase, isPauseable
  • Constructor Details

    • RabbitAmqpListenerContainer

      public RabbitAmqpListenerContainer(AmqpConnectionFactory connectionFactory)
      Construct an instance based on the provided AmqpConnectionFactory.
      Parameters:
      connectionFactory - to use.
  • Method Details

    • setQueueNames

      public void setQueueNames(String... queueNames)
      Specified by:
      setQueueNames in interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
    • setInitialCredits

      public void setInitialCredits(int initialCredits)
      The initial number credits to grant to the AMQP receiver. The default is 100.
      Parameters:
      initialCredits - number of initial credits
      See Also:
      • ConsumerBuilder.initialCredits(int)
    • setPriority

      public void setPriority(int priority)
      The consumer priority.
      Parameters:
      priority - consumer priority
      See Also:
      • ConsumerBuilder.priority(int)
    • setStateListeners

      public void setStateListeners(com.rabbitmq.client.amqp.Resource.StateListener... stateListeners)
      Add Resource.StateListener instances to the consumer.
      Parameters:
      stateListeners - listeners to add
      See Also:
      • ConsumerBuilder.listeners(Resource.StateListener...)
    • setAfterReceivePostProcessors

      public void setAfterReceivePostProcessors(org.springframework.amqp.core.MessagePostProcessor... afterReceivePostProcessors)
      Set MessagePostProcessors that will be applied after message reception, before invoking the MessageListener. Often used to decompress data. Processors are invoked in order, depending on PriorityOrder, Order and 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 or setBatchSize(int). Default 30 seconds.
      Parameters:
      batchReceiveTimeout - the timeout for gathering a batch.
    • setTaskScheduler

      public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
      Set a TaskScheduler for monitoring batch releases.
      Parameters:
      taskScheduler - the TaskScheduler to use.
    • setBeanName

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

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

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

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

      public void setAutoSettle(boolean autoSettle)
      Set to false to propagate a MessageProperties.setAmqpAcknowledgment(AmqpAcknowledgment) for target MessageListener manual settlement. In case of RabbitAmqpMessageListener, the native Consumer.Context should be used for manual settlement.
      Parameters:
      autoSettle - to call Consumer.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 throwing AmqpRejectAndDontRequeueException or ImmediateRequeueAmqpException from the message listener. Default true.
      Parameters:
      defaultRequeue - true to requeue by default.
    • 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)
    • setListenerId

      public void setListenerId(String id)
      Specified by:
      setListenerId in interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
    • getListenerId

      public String getListenerId()
      The 'id' attribute of the listener.
      Returns:
      the id (or the container bean name if no id set).
    • setupMessageListener

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

      public @Nullable Object getMessageListener()
      Specified by:
      getMessageListener in interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Specified by:
      afterPropertiesSet in interface org.springframework.amqp.rabbit.listener.MessageListenerContainer
    • isRunning

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

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

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

      public void pause(String queueName)
      Pause all the consumer for specific queue.
    • resume

      public void resume(String queueName)
      Resume all the consumer for specific queue.
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean