Interface BatchInterceptor
- All Known Subinterfaces:
MappingBatchInterceptor
- All Known Implementing Classes:
BatchInterceptor.FilterPreserving, 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.
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 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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordExplicit selection-preserving wrapper; usepreservingConsumerFilter(BatchInterceptor). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<BatchInterceptor> Default batch interceptors discovered via Java's service loader, sorted byOrder. -
Method Summary
Modifier and TypeMethodDescriptiondefault BatchInterceptorandThen(BatchInterceptor nextInterceptor) Composes this interceptor with another, returning a new interceptor that applies both in sequence.default ConsumerFilterdescribeConsumerFilter(ConsumerFilter downstream) Describes serialized inputs needed by this interceptor and its downstream consumer.static List<BatchInterceptor> effectiveInterceptors(ConsumerConfiguration configuration, MessageType type, Fluxzero fluxzero) Ordered application and consumer interceptors, shared by execution and input selection.intercept(Consumer<MessageBatch> consumer, Tracker tracker) Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.static BatchInterceptorjoin(List<BatchInterceptor> interceptors) Joins a list of interceptors into a single composite interceptor, applying them in sequence.static BatchInterceptornoOp()Returns a no-op interceptor that does not alter the consumer behavior.static BatchInterceptorpreservingConsumerFilter(BatchInterceptor interceptor) Marks an interceptor as preserving downstream selection.default voidOptional lifecycle callback for cleanup when the tracker shuts down.
-
Field Details
-
defaultInterceptors
Default batch interceptors discovered via Java's service loader, sorted byOrder. These interceptors are applied automatically by Fluxzero.
-
-
Method Details
-
noOp
Returns a no-op interceptor that does not alter the consumer behavior. -
describeConsumerFilter
Describes serialized inputs needed by this interceptor and its downstream consumer. The default is unrestricted because interceptors can transform messages or require inputs that no handler accepts. Implementations may returndownstreamonly when excluded inputs are irrelevant to their behavior and they never transform an excluded input into one the downstream filter admits. Custom inverse projections describe the input side of a transformation; this method runs after serializer/upcaster projection. -
preservingConsumerFilter
Marks an interceptor as preserving downstream selection. Use for observers that only need handler-relevant messages and do not expand the accepted inputs. This is an explicit promise, not an analysis of the lambda. Invocation, shutdown and the wrapped interceptor'sOrderare preserved. -
effectiveInterceptors
static List<BatchInterceptor> effectiveInterceptors(ConsumerConfiguration configuration, MessageType type, Fluxzero fluxzero) Ordered application and consumer interceptors, shared by execution and input selection. -
intercept
Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.- Parameters:
consumer- the original consumer that processes theMessageBatchtracker- the tracker invoking this interceptor- Returns:
- a wrapped consumer with additional behavior
-
shutdown
Optional lifecycle callback for cleanup when the tracker shuts down. Default is a no-op.- Parameters:
tracker- the tracker being shut down
-
andThen
Composes this interceptor with another, returning a new interceptor that applies both in sequence. ThenextInterceptoris applied first, followed by this interceptor.- Parameters:
nextInterceptor- the interceptor to apply before this one- Returns:
- a combined interceptor
-
join
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
-