Interface Consumer.Context

All Known Subinterfaces:
Consumer.BatchContext
Enclosing interface:
Consumer

public static interface Consumer.Context
Context for message processing.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Accept the message (AMQP 1.0 accepted outcome).
    batch(int batchSizeHint)
    Create a batch context to accumulate message contexts and settle them at once.
    void
    defer(String deferralToken, Duration delay)
    Requeue the message for redelivery after the specified delay, and park it under a deferral token so it can also be retrieved early with Consumer.claimDeferred(String...).
    void
    defer(String deferralToken, Instant deliveryTime)
    Requeue the message for redelivery at the specified time, and park it under a deferral token so it can also be retrieved early with Consumer.claimDeferred(String...).
    void
    Requeue the message for redelivery after the specified delay.
    void
    delayedRetry(Duration delay, boolean deliveryFailed)
    Requeue the message for redelivery after the specified delay.
    void
    delayedRetry(Instant deliveryTime)
    Requeue the message for redelivery at the specified time.
    void
    delayedRetry(Instant deliveryTime, boolean deliveryFailed)
    Requeue the message for redelivery at the specified time.
    void
    Discard the message (AMQP 1.0 rejected outcome).
    void
    discard(Map<String,Object> annotations)
    Discard the message with annotations to combine with the existing message annotations.
    void
    Requeue the message (AMQP 1.0 released outcome).
    void
    requeue(Map<String,Object> annotations)
    Requeue the message with annotations to combine with the existing message annotations.
    void
    requeue(Map<String,Object> annotations, boolean deliveryFailed)
    Requeue the message with annotations to combine with the existing message annotations.
  • Method Details

    • accept

      void accept()
      Accept the message (AMQP 1.0 accepted outcome).

      This means the message has been processed and the broker can delete it.

    • discard

      void discard()
      Discard the message (AMQP 1.0 rejected outcome).

      This means the message cannot be processed because it is invalid, the broker can drop it or dead-letter it if it is configured.

    • discard

      void discard(Map<String,Object> annotations)
      Discard the message with annotations to combine with the existing message annotations.

      This means the message cannot be processed because it is invalid, the broker can drop it or dead-letter it if it is configured.

      Custom application-specific annotation keys should start with the x-opt- prefix so they are safely ignored if not understood. Keys starting with x- (but not x-opt-) are reserved for broker-specific features, and unrecognized keys will cause a protocol error.

      This maps to the AMQP 1.0 modified{delivery-failed = true, undeliverable-here = true} outcome.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      annotations - message annotations to combine with existing ones
      See Also:
    • requeue

      void requeue()
      Requeue the message (AMQP 1.0 released outcome).

      This means the message has not been processed and the broker can requeue it and deliver it to the same or a different consumer.

    • requeue

      void requeue(Map<String,Object> annotations)
      Requeue the message with annotations to combine with the existing message annotations.

      This means the message has not been processed and the broker can requeue it and deliver it to the same or a different consumer.

      Custom application-specific annotation keys should start with the x-opt- prefix so they are safely ignored if not understood. Keys starting with x- (but not x-opt-) are reserved for broker-specific features, and unrecognized keys will cause a protocol error.

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      annotations - message annotations to combine with existing ones
      See Also:
    • requeue

      void requeue(Map<String,Object> annotations, boolean deliveryFailed)
      Requeue the message with annotations to combine with the existing message annotations.

      This means the message has not been processed and the broker can requeue it and deliver it to the same or a different consumer.

      Custom application-specific annotation keys should start with the x-opt- prefix so they are safely ignored if not understood. Keys starting with x- (but not x-opt-) are reserved for broker-specific features, and unrecognized keys will cause a protocol error.

      This maps to the AMQP 1.0 modified{delivery-failed = deliveryFailed, undeliverable-here = false} outcome.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      annotations - message annotations to combine with existing ones
      deliveryFailed - if true, the delivery count of the message is incremented
      See Also:
    • delayedRetry

      void delayedRetry(Duration delay)
      Requeue the message for redelivery after the specified delay.

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to now + delay.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      delay - delivery delay from now
      See Also:
    • delayedRetry

      void delayedRetry(Duration delay, boolean deliveryFailed)
      Requeue the message for redelivery after the specified delay.

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to now + delay.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      delay - delivery delay from now
      deliveryFailed - if true, the delivery count of the message is incremented
      See Also:
    • delayedRetry

      void delayedRetry(Instant deliveryTime)
      Requeue the message for redelivery at the specified time.

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to the specified time.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      deliveryTime - absolute delivery time
      See Also:
    • delayedRetry

      void delayedRetry(Instant deliveryTime, boolean deliveryFailed)
      Requeue the message for redelivery at the specified time.

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to the specified time.

      Only quorum queues support the modification of message annotations with the modified outcome.

      Parameters:
      deliveryTime - absolute delivery time
      deliveryFailed - if true, the delivery count of the message is incremented
      See Also:
    • defer

      void defer(String deferralToken, Duration delay)
      Requeue the message for redelivery after the specified delay, and park it under a deferral token so it can also be retrieved early with Consumer.claimDeferred(String...).

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to now + delay and the x-opt-deferral-token annotation set to deferralToken.

      The token is honoured only because a delivery time is also set: a deferral token cannot be supplied without one, since the broker would otherwise silently ignore it. The message still becomes available at its delivery time even if the token is never claimed. If the token has already been used for another message, claiming it delivers both, oldest first. The token is readable on the redelivered message through its x-opt-deferral-token annotation.

      Only quorum queues support deferral tokens.

      Requires RabbitMQ 4.4 or more.

      This is an experimental API, subject to change.

      Parameters:
      deferralToken - the token the message is parked under, at most 256 UTF-8 bytes
      delay - delivery delay from now
      Since:
      1.7.0
      See Also:
    • defer

      void defer(String deferralToken, Instant deliveryTime)
      Requeue the message for redelivery at the specified time, and park it under a deferral token so it can also be retrieved early with Consumer.claimDeferred(String...).

      This maps to the AMQP 1.0 modified{delivery-failed = false, undeliverable-here = false} outcome with the x-opt-delivery-time annotation set to the specified time and the x-opt-deferral-token annotation set to deferralToken.

      The token is honoured only if deliveryTime is in the future: a deferral token cannot be supplied without one, since the broker would otherwise silently ignore it. The message still becomes available at its delivery time even if the token is never claimed. If the token has already been used for another message, claiming it delivers both, oldest first. The token is readable on the redelivered message through its x-opt-deferral-token annotation.

      Only quorum queues support deferral tokens.

      Requires RabbitMQ 4.4 or more.

      This is an experimental API, subject to change.

      Parameters:
      deferralToken - the token the message is parked under, at most 256 UTF-8 bytes
      deliveryTime - absolute delivery time, must be in the future
      Since:
      1.7.0
      See Also:
    • batch

      Consumer.BatchContext batch(int batchSizeHint)
      Create a batch context to accumulate message contexts and settle them at once.

      The message context the batch context is created from is not added to the batch context.

      Returns:
      the created batch context