Interface BatchInterceptor
- All Known Subinterfaces:
MappingBatchInterceptor
- All Known Implementing Classes:
DisableMetrics
,FluxCapacitorInterceptor
,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.
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:
-
Method Summary
Modifier and TypeMethodDescriptiondefault BatchInterceptor
andThen
(BatchInterceptor nextInterceptor) Composes this interceptor with another, returning a new interceptor that applies both in sequence.intercept
(Consumer<MessageBatch> consumer, Tracker tracker) Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.static BatchInterceptor
join
(List<BatchInterceptor> interceptors) Joins a list of interceptors into a single composite interceptor, applying them in sequence.static BatchInterceptor
noOp()
Returns a no-op interceptor that does not alter the consumer behavior.default void
Optional lifecycle callback for cleanup when the tracker shuts down.
-
Method Details
-
noOp
Returns a no-op interceptor that does not alter the consumer behavior. -
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 theMessageBatch
tracker
- 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. ThenextInterceptor
is 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
-