Interface BatchInterceptor

All Known Subinterfaces:
MappingBatchInterceptor
All Known Implementing Classes:
DisableMetrics, FluxzeroInterceptor, StallingBatchInterceptor, TrackerMonitor
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 BatchInterceptor
Intercepts and decorates batch-level message handling for a Tracker.

A BatchInterceptor wraps the execution of a Consumer<MessageBatch>—typically invoked by a tracker to process a group of messages polled from the message log. Interceptors can be used to inject common behavior such as logging, metrics, retries, transaction boundaries, or diagnostics at the batch level.

Implementations can also be registered via Java's

invalid reference
ServiceLoader
. Service-loaded interceptors are picked up automatically by Fluxzero, including when using the TestFixture, and are ordered using @Order.

Usage

Interceptors are applied during consumer configuration via the Consumer.batchInterceptors() attribute, or programmatically. They are composed in a chain using andThen(BatchInterceptor) or join(List).

Example

public class LoggingBatchInterceptor implements BatchInterceptor {
    @Override
    public Consumer<MessageBatch> intercept(Consumer<MessageBatch> consumer, Tracker tracker) {
        return batch -> {
            log.info("Processing batch of {} messages", batch.size());
            consumer.accept(batch);
            log.info("Finished processing batch");
        };
    }
}
See Also:
  • Field Details

    • defaultInterceptors

      static final List<BatchInterceptor> defaultInterceptors
      Default batch interceptors discovered via Java's service loader, sorted by Order. These interceptors are applied automatically by Fluxzero.
  • Method Details

    • noOp

      static BatchInterceptor noOp()
      Returns a no-op interceptor that does not alter the consumer behavior.
    • intercept

      Consumer<MessageBatch> intercept(Consumer<MessageBatch> consumer, Tracker tracker)
      Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.
      Parameters:
      consumer - the original consumer that processes the MessageBatch
      tracker - the tracker invoking this interceptor
      Returns:
      a wrapped consumer with additional behavior
    • shutdown

      default void shutdown(Tracker tracker)
      Optional lifecycle callback for cleanup when the tracker shuts down. Default is a no-op.
      Parameters:
      tracker - the tracker being shut down
    • andThen

      default BatchInterceptor andThen(BatchInterceptor nextInterceptor)
      Composes this interceptor with another, returning a new interceptor that applies both in sequence. The nextInterceptor is applied first, followed by this interceptor.
      Parameters:
      nextInterceptor - the interceptor to apply before this one
      Returns:
      a combined interceptor
    • join

      static BatchInterceptor join(List<BatchInterceptor> interceptors)
      Joins a list of interceptors into a single composite interceptor, applying them in sequence. If the list is empty, a no-op interceptor is returned.
      Parameters:
      interceptors - the list of interceptors to join
      Returns:
      a composite interceptor