Class RedisOutboxBackoff

java.lang.Object
com.aim2be.platform.outbox.redis.RedisOutboxBackoff

public final class RedisOutboxBackoff extends Object
Exponential-backoff calculator for the failure re-score of the :pending sorted-set (refinement #5 — score by nextAttemptAt, not createdAt, so a Kafka outage does not hot-loop the oldest entries).

The delay for a given attempt count is min(base * 2^attempt, max). attempt is the entry's CURRENT retries value (0 on the first failure → base; 1 → 2*base; etc.). The shift is computed in long with an overflow guard so a large attempt count saturates to max rather than wrapping negative.

Immutable + thread-safe.

  • Constructor Details

    • RedisOutboxBackoff

      public RedisOutboxBackoff(long baseMs, long maxMs)
      Parameters:
      baseMs - base delay in ms (attempt 0); must be ≥ 1
      maxMs - ceiling delay in ms; must be ≥ baseMs
  • Method Details

    • from

      public static RedisOutboxBackoff from(RedisOutboxProperties.Poller poller)
      Builds a backoff from the poller properties.
      Parameters:
      poller - the poller config carrying backoffBaseMs + backoffMaxMs; never null
      Returns:
      a configured backoff
    • delayMs

      public long delayMs(int attempt)
      Parameters:
      attempt - the entry's current retries count (0-based; the first failure passes 0). Negative inputs are clamped to 0.
      Returns:
      the backoff delay in ms, capped at maxMs