Class BackoffPolicy

java.lang.Object
org.apache.pulsar.client.api.v5.config.BackoffPolicy

public final class BackoffPolicy extends Object
Backoff configuration for broker reconnection attempts.

The base delay for attempt n is min(initialInterval * multiplier^(n-1), maxInterval). A symmetric random jitter of ±jitterPercent/2 is applied to each delay (including the first one) to spread out concurrent retries.

Use fixed(Duration, Duration) or exponential(Duration, Duration) for the common cases, or builder() to configure all knobs explicitly.

  • Field Details

    • DEFAULT_JITTER_PERCENT

      public static final double DEFAULT_JITTER_PERCENT
      Default jitter percentage applied when not explicitly specified.
      See Also:
  • Method Details

    • initialInterval

      public Duration initialInterval()
      Returns:
      the base delay before the first reconnection attempt
    • maxInterval

      public Duration maxInterval()
      Returns:
      the maximum delay between reconnection attempts
    • multiplier

      public double multiplier()
      Returns:
      the multiplier applied after each attempt
    • jitterPercent

      public double jitterPercent()
      Returns:
      the symmetric jitter percentage applied to each delay; 0 means no jitter
    • fixed

      public static BackoffPolicy fixed(Duration initialInterval, Duration maxInterval)
      Create a fixed backoff (no increase between retries) with the default jitter.
      Parameters:
      initialInterval - the constant base delay between reconnection attempts
      maxInterval - the maximum delay between reconnection attempts
      Returns:
      a BackoffPolicy with a multiplier of 1.0 and the default jitter
    • exponential

      public static BackoffPolicy exponential(Duration initialInterval, Duration maxInterval)
      Create an exponential backoff with the given bounds, a default multiplier of 2 and the default jitter.
      Parameters:
      initialInterval - the base delay before the first reconnection attempt
      maxInterval - the maximum delay between reconnection attempts
      Returns:
      a BackoffPolicy with a multiplier of 2.0 and the default jitter
    • builder

      public static BackoffPolicy.Builder builder()
      Returns:
      a new builder for constructing a BackoffPolicy