Interface MessageConsumer

All Superinterfaces:
AutoCloseable

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

    Modifier and Type
    Method
    Description
    long
     
    void
    Stops consuming, letting in-flight deliveries settle.
    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.

      The difference between this and close() is what happens to work in progress. Closing cancels the subscription and lets whatever was mid-handler settle however it settles; draining cancels the subscription and then waits, so a consumer being removed finishes its work rather than having it redelivered somewhere else.

      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, letting in-flight deliveries settle.
      Specified by:
      close in interface AutoCloseable