Interface KafkaShareConsumer<K,V>
- Type Parameters:
K- the type of keyV- the type of value
- All Known Implementing Classes:
ReactiveKafkaShareConsumer
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 TypeMethodDescriptionio.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> commit()Commits the offsetsio.smallrye.mutiny.Uni<Void> Commits the offsets asynchronouslyio.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.unwrap()
-
Method Details
-
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
KafkaShareConsumerand that returns a result (potentiallynull). The producedUniemits the returned result when the action completes. If the action throws an exception, the producedUniemits 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 beVoid- Parameters:
action- the action to execute, must not benull- 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 producedUniemitsnullwhen the action completes. If the action throws an exception, the producedUniemits the exception as failure.- Parameters:
action- the action, must not benull- Returns:
- the Uni emitting
nullor the failure when the action completes.
-
unwrap
- Returns:
- the underlying share consumer. Be aware that to use it you needs to be on the polling thread.
-
commit
Commits the offsets- Returns:
- the Uni emitting
nullwhen the commit has been executed.
-
commitAsync
io.smallrye.mutiny.Uni<Void> commitAsync()Commits the offsets asynchronously- Returns:
- the Uni emitting
nullwhen the commit has been executed.
-
acknowledge
io.smallrye.mutiny.Uni<Void> acknowledge(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> record) - Returns:
-
acknowledge
-