Interface MessageConsumer

All Superinterfaces:
AutoCloseable

public interface MessageConsumer extends AutoCloseable
A running consumer.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    void
    Stops consuming: cancels the subscription, waits up to 20 seconds for the handler that is running to finish and be acknowledged, then releases the channel.
    long
     
    boolean
    drain(Duration timeout)
    Stops taking new messages and waits for the ones in hand to finish.
    long
     
    long
     
    boolean
     
    boolean
     
    void
    Stops taking new messages, keeping the consumer able to start again.
    int
     
    void
    prefetch(int prefetch)
    Changes how many unsettled deliveries this consumer may hold, while it is running.
     
    long
     
    void
    Starts taking messages again after pause().
    long
     
  • Method Details

    • queue

      String queue()
      Returns:
      the queue being consumed
    • isRunning

      boolean isRunning()
      Returns:
      whether it is still receiving deliveries
    • acknowledged

      long acknowledged()
      Returns:
      how many messages have been acknowledged
    • rejected

      long rejected()
      Returns:
      how many messages have been rejected after a handler failure
    • duplicates

      long duplicates()
      Returns:
      how many deliveries were recognised as already handled and acknowledged without running the handler; zero unless an idempotency store is configured
    • retried

      long retried()
      Returns:
      how many messages have been sent to a retry queue for another attempt
    • deadLettered

      long deadLettered()
      Returns:
      how many messages have been dead-lettered or parked
    • inFlight

      long inFlight()
      Returns:
      how many messages this consumer is handling right now. Zero means it can be stopped without manufacturing a redelivery
    • drain

      boolean drain(Duration timeout)
      Stops taking new messages and waits for the ones in hand to finish.

      Draining cancels the subscription and then waits, so a consumer being removed finishes its work rather than having it redelivered somewhere else. close() does the same with a fixed 20-second wait and then releases the channel; drain first to choose the wait yourself.

      That matters whenever a handler is not idempotent, and it is the primitive a blue-green deployment needs: drain the old side, then cut over.

      Parameters:
      timeout - how long to wait for in-flight messages
      Returns:
      true if everything finished, false if the timeout passed first — in which case the consumer is still stopped, but something is still running
    • prefetch

      void prefetch(int prefetch)
      Changes how many unsettled deliveries this consumer may hold, while it is running.

      Takes effect for deliveries after the call. Messages already in flight are unaffected, because they have been sent and there is no way to un-send them.

      Parameters:
      prefetch - the new limit, at least 1
    • prefetch

      int prefetch()
      Returns:
      the prefetch currently in force
    • pause

      void pause()
      Stops taking new messages, keeping the consumer able to start again.

      Different from drain(java.time.Duration) in intent rather than mechanism: pausing is reversible and does not wait. Messages already being handled finish; nothing new is delivered until resume().

      What a maintenance window wants, and what the consuming half of a blue-green cutover wants before it commits to stopping.

    • resume

      void resume()
      Starts taking messages again after pause(). Does nothing if not paused.
    • isPaused

      boolean isPaused()
      Returns:
      whether this consumer is paused rather than stopped
    • close

      void close()
      Stops consuming: cancels the subscription, waits up to 20 seconds for the handler that is running to finish and be acknowledged, then releases the channel.

      Nothing new is handed to a handler once this is called. A handler still running after the wait has its message redelivered. Since 0.7.19; until then close did not wait, and a message being handled during close was redelivered and handled again. Called from inside this consumer's own handler, it does not wait for that handler.

      Specified by:
      close in interface AutoCloseable