Interface KafkaShareConsumer<K,V>

Type Parameters:
K - the type of key
V - the type of value
All Known Implementing Classes:
ReactiveKafkaShareConsumer

public interface KafkaShareConsumer<K,V>
Kafka Share Consumer API.

Unlike ShareConsumer, this API is asynchronous and makes sure that the actions are executed on the Kafka polling thread.

Share consumers are designed for cooperative consumption across multiple consumers without explicit partition assignment. Records are automatically distributed among share group members, and acknowledgment is managed through commits.

  • Method Summary

    Modifier and Type
    Method
    Description
    io.smallrye.mutiny.Uni<Void>
    acknowledge(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
     
    io.smallrye.mutiny.Uni<Void>
    acknowledge(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record, org.apache.kafka.clients.consumer.AcknowledgeType type)
     
    io.smallrye.mutiny.Uni<Void>
    Commits the offsets
    io.smallrye.mutiny.Uni<Void>
    Commits the offsets asynchronously
     
    io.smallrye.mutiny.Uni<Void>
    runOnPollingThread(Consumer<org.apache.kafka.clients.consumer.ShareConsumer<K,V>> action)
    Runs an action on the polling thread.
    <R> io.smallrye.mutiny.Uni<R>
    runOnPollingThread(Function<org.apache.kafka.clients.consumer.ShareConsumer<K,V>,R> action)
    Runs an action on the polling thread.
    org.apache.kafka.clients.consumer.ShareConsumer<K,V>
     
  • Method Details

    • configuration

      Map<String,?> configuration()
      Returns:
      Kafka share consumer configuration
    • runOnPollingThread

      @CheckReturnValue <R> io.smallrye.mutiny.Uni<R> runOnPollingThread(Function<org.apache.kafka.clients.consumer.ShareConsumer<K,V>,R> action)
      Runs an action on the polling thread.

      The action is a function taking as parameter the KafkaShareConsumer and that returns a result (potentially null). The produced Uni emits the returned result when the action completes. If the action throws an exception, the produced Uni emits the exception as failure.

      If the action does not return a result, use runOnPollingThread(java.util.function.Consumer).

      Type Parameters:
      R - the type of result, can be Void
      Parameters:
      action - the action to execute, must not be null
      Returns:
      the Uni emitting the result or the failure when the action completes.
    • runOnPollingThread

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> runOnPollingThread(Consumer<org.apache.kafka.clients.consumer.ShareConsumer<K,V>> action)
      Runs an action on the polling thread.

      The action is a consumer receiving the KafkaShareConsumer. The produced Uni emits null when the action completes. If the action throws an exception, the produced Uni emits the exception as failure.

      Parameters:
      action - the action, must not be null
      Returns:
      the Uni emitting null or the failure when the action completes.
    • unwrap

      org.apache.kafka.clients.consumer.ShareConsumer<K,V> unwrap()
      Returns:
      the underlying share consumer. Be aware that to use it you needs to be on the polling thread.
    • commit

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> commit()
      Commits the offsets
      Returns:
      the Uni emitting null when the commit has been executed.
    • commitAsync

      io.smallrye.mutiny.Uni<Void> commitAsync()
      Commits the offsets asynchronously
      Returns:
      the Uni emitting null when the commit has been executed.
    • acknowledge

      io.smallrye.mutiny.Uni<Void> acknowledge(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
      Returns:
    • acknowledge

      io.smallrye.mutiny.Uni<Void> acknowledge(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record, org.apache.kafka.clients.consumer.AcknowledgeType type)