Interface Consumer

All Superinterfaces:
AutoCloseable, Resource

public interface Consumer extends AutoCloseable, Resource
API to consume messages from a RabbitMQ queue.

Instances are configured and created with a ConsumerBuilder.

See Also:
  • Method Details

    • pause

      void pause()
      Pause the consumer to stop receiving messages.

      Messages already in flight when this method is called may still be delivered after it returns.

      Throws:
      AmqpException - if the consumer is not open
    • unsettledMessageCount

      long unsettledMessageCount()
      Return the number of unsettled messages.
      Returns:
      unsettled message count
    • unpause

      void unpause()
      Request to receive messages again.
      Throws:
      AmqpException - if the consumer is not open
    • close

      void close()
      Close the consumer with its resources.
      Specified by:
      close in interface AutoCloseable
    • claimDeferred

      void claimDeferred(String... tokens)
      Claim messages previously deferred with a Consumer.Context.defer(String, java.time.Duration) token, so they are redelivered ahead of their scheduled delivery time.

      A token may have been used for more than one message, in which case claiming it can deliver more than one message, oldest first. Claiming an unknown token has no effect: it is silently ignored by the broker. A claim does not grant extra credit: claimed messages are delivered as the consumer's existing credit allows.

      Claims do not survive connection recovery: the application must claim tokens again after the consumer recovers.

      Only quorum queues support deferral tokens.

      Requires RabbitMQ 4.4 or more.

      This is an experimental API, subject to change.

      Parameters:
      tokens - the tokens to claim
      Throws:
      AmqpException - if the consumer is not open
      AmqpException - if the queue this consumer is attached to does not support deferral tokens
      Since:
      1.7.0
      See Also: