Interface MappingBatchInterceptor

All Superinterfaces:
BatchInterceptor, BiFunction<io.fluxzero.common.api.tracking.MessageBatch,Tracker,io.fluxzero.common.api.tracking.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<io.fluxzero.common.api.tracking.MessageBatch,Tracker,io.fluxzero.common.api.tracking.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:

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 Summary

    Modifier and Type
    Method
    Description
    io.fluxzero.common.api.tracking.MessageBatch
    apply(io.fluxzero.common.api.tracking.MessageBatch messageBatch, Tracker tracker)
    Applies a transformation to the given MessageBatch, optionally modifying its contents or structure.
    default Consumer<io.fluxzero.common.api.tracking.MessageBatch>
    intercept(Consumer<io.fluxzero.common.api.tracking.MessageBatch> consumer, Tracker tracker)
    Wraps the batch processing consumer with a transformation step that rewrites the batch before processing.

    Methods inherited from interface io.fluxzero.sdk.tracking.BatchInterceptor

    andThen, shutdown

    Methods inherited from interface java.util.function.BiFunction

    andThen
  • Method Details

    • apply

      io.fluxzero.common.api.tracking.MessageBatch apply(io.fluxzero.common.api.tracking.MessageBatch messageBatch, Tracker tracker)
      Applies a transformation to the given MessageBatch, optionally modifying its contents or structure.
      Specified by:
      apply in interface BiFunction<io.fluxzero.common.api.tracking.MessageBatch,Tracker,io.fluxzero.common.api.tracking.MessageBatch>
      Parameters:
      messageBatch - the incoming message batch
      tracker - the tracker handling the batch
      Returns:
      the transformed batch to be passed to the next consumer
    • intercept

      default Consumer<io.fluxzero.common.api.tracking.MessageBatch> intercept(Consumer<io.fluxzero.common.api.tracking.MessageBatch> consumer, Tracker tracker)
      Wraps the batch processing consumer with a transformation step that rewrites the batch before processing.
      Specified by:
      intercept in interface BatchInterceptor
      Parameters:
      consumer - the original consumer that processes the MessageBatch
      tracker - the tracker invoking this interceptor
      Returns:
      a wrapped consumer with additional behavior