Interface MessageHandler<T>

Type Parameters:
T - decoded payload type
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MessageHandler<T>
Handles one message.

The outcome is expressed by returning or throwing, which keeps the common case free of ceremony:

  • return normally to accept the message;
  • throw AceRetryableException to send it to the next retry tier;
  • throw AceFatalException to dead-letter it without spending retries;
  • throw anything else and the configured error classifier decides, defaulting to retry.

Handlers that want to state the outcome directly should implement AckAwareHandler instead.

A handler must never sleep in order to retry. Throw, and let RetryPolicy decide: a short wait is held by the engine, which knows the attempt count and can put the message back with it advanced, and a long one is handed to the broker so that a waiting message does not hold a delivery slot at all. A sleep inside the handler does neither, and loses the attempt count when the process restarts.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handle(Message<T> message)
     
  • Method Details

    • handle

      void handle(Message<T> message) throws Exception
      Parameters:
      message - the delivery to handle
      Throws:
      Exception - to signal failure; the type decides whether it is retried