Class OrderedStreamHandler

java.lang.Object
io.smallrye.reactive.messaging.kafka.commit.ContextHolder
io.smallrye.reactive.messaging.kafka.impl.OrderedStreamHandler
All Implemented Interfaces:
KafkaCommitHandler

public class OrderedStreamHandler extends ContextHolder implements KafkaCommitHandler
A KafkaCommitHandler wrapper that applies ordering guarantees for concurrent processing.

Messages are grouped (by key or partition) and each group processes messages sequentially, while different groups can process concurrently. All other commit handler operations are delegated to the underlying handler.

This strategy supports concurrent processing with ordering guarantees using the `throttled.ordered` configuration. Messages are grouped (by key or partition) and each group processes messages sequentially, while different groups can process concurrently. See ProcessingOrder for available modes.

This decorator works with any commit strategy, but it is particularly useful with the throttled strategy, as it allows to process messages in order while still benefiting from concurrency.

See Also:
  • Constructor Details

  • Method Details

    • capture

      public void capture(io.vertx.mutiny.core.Context context)
      Overrides:
      capture in class ContextHolder
    • capture

      public void capture(io.vertx.core.Context context)
      Overrides:
      capture in class ContextHolder
    • decorateStream

      public <K, V> io.smallrye.mutiny.Multi<IncomingKafkaRecord<K,V>> decorateStream(io.smallrye.mutiny.Multi<IncomingKafkaRecord<K,V>> consumed)
      Description copied from interface: KafkaCommitHandler
      Decorates the stream of consumed Kafka records.

      This method allows commit handlers to transform the incoming stream of records

      Specified by:
      decorateStream in interface KafkaCommitHandler
      Type Parameters:
      K - type of record key
      V - type of record value
      Parameters:
      consumed - the stream of consumed Kafka records
      Returns:
      the decorated stream of Kafka records
    • received

      public <K, V> io.smallrye.mutiny.Uni<IncomingKafkaRecord<K,V>> received(IncomingKafkaRecord<K,V> record)
      Description copied from interface: KafkaCommitHandler
      Called on message received but before calling the processing function. Returned Uni allows chaining asynchronous actions before message processing.
      Specified by:
      received in interface KafkaCommitHandler
      Type Parameters:
      K - type of record key
      V - type of record value
      Parameters:
      record - incoming Kafka record
      Returns:
      the Uni yielding the received record
    • handle

      public <K, V> io.smallrye.mutiny.Uni<Void> handle(IncomingKafkaRecord<K,V> record)
      Description copied from interface: KafkaCommitHandler
      Handle message acknowledgment
      Specified by:
      handle in interface KafkaCommitHandler
      Type Parameters:
      K - type of record key
      V - type of record value
      Parameters:
      record - incoming Kafka record
      Returns:
      a completion stage completed when the message is acknowledged.
    • terminate

      public void terminate(boolean graceful)
      Description copied from interface: KafkaCommitHandler
      Called on channel shutdown
      Specified by:
      terminate in interface KafkaCommitHandler
      Parameters:
      graceful - true if it is a graceful shutdown
    • partitionsAssigned

      public void partitionsAssigned(Collection<org.apache.kafka.common.TopicPartition> partitions)
      Description copied from interface: KafkaCommitHandler
      Called on partitions assigned on Kafka rebalance listener
      Specified by:
      partitionsAssigned in interface KafkaCommitHandler
      Parameters:
      partitions - assigned partitions
    • partitionsRevoked

      public void partitionsRevoked(Collection<org.apache.kafka.common.TopicPartition> partitions)
      Description copied from interface: KafkaCommitHandler
      Called on partitions revokd on Kafka rebalance listener
      Specified by:
      partitionsRevoked in interface KafkaCommitHandler
      Parameters:
      partitions - revoked partitions
    • getDelegate

      public KafkaCommitHandler getDelegate()
      Returns the underlying commit handler.