Class RabbitAmqpListenerContainer

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

public class RabbitAmqpListenerContainer extends Object implements MessageListenerContainer, BeanNameAware, DisposableBean
A listener container for RabbitMQ AMQP 1.0 Consumer.
Since:
4.0
Author:
Artem Bilan
  • 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)
      Description copied from interface: MessageListenerContainer
      Set the queue names or AMQP 1.0 addresses.
      Specified by:
      setQueueNames in interface MessageListenerContainer
      Parameters:
      queueNames - the queue names.
    • 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(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(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 BeanNameAware
    • 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
    • setAdviceChain

      public void setAdviceChain(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(ErrorHandler errorHandler)
    • 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).
    • 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.
    • afterPropertiesSet

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

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
    • 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
    • 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 DisposableBean