Interface MappingBatchInterceptor

All Superinterfaces:
BatchInterceptor, BiFunction<MessageBatch, Tracker, MessageBatch>
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 MappingBatchInterceptor extends BatchInterceptor, BiFunction<MessageBatch, Tracker, MessageBatch>
A BatchInterceptor specialization that transforms a MessageBatch before it is passed to the consumer for processing.

This interface combines BatchInterceptor with a BiFunction contract, allowing implementors to declaratively map a batch in-place:

  • Filter out or modify messages within the batch
  • Augment batch metadata or headers
  • Replace or rewrap the entire batch

Design:

  • This is a functional interface. Implementors only need to define apply(MessageBatch, Tracker).
  • The intercept(Consumer, Tracker) method delegates directly to the apply(...) transformation before passing the result to the next consumer.
  • Provides a clean entry point for small, functional batch manipulation use cases.

Example Usage

MappingBatchInterceptor maskingInterceptor = (batch, tracker) -> {
    List<Message> maskedMessages = batch.getMessages().stream()
        .map(m -> m.withMetadata(m.getMetadata().and("masked", true)))
        .toList();
    return batch.withMessages(maskedMessages);
};

ConsumerConfiguration.builder()
    .name("maskedConsumer")
    .batchInterceptor(maskingInterceptor)
    .build();

Best Practices:

  • For non-transformational logic (like delaying or thread context management), prefer BatchInterceptor directly.
  • Use MappingBatchInterceptor when your logic results in a modified or filtered batch.
See Also:
  • Method Details