Class ReactiveKafkaConsumer<K,V>
- java.lang.Object
-
- io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaConsumer<K,V>
-
- All Implemented Interfaces:
KafkaConsumer<K,V>
public class ReactiveKafkaConsumer<K,V> extends Object implements KafkaConsumer<K,V>
-
-
Constructor Summary
Constructors Constructor Description ReactiveKafkaConsumer(KafkaConnectorIncomingConfiguration config, KafkaSource<K,V> source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()io.smallrye.mutiny.Uni<Void>commit(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> map)Commits the offsetsio.smallrye.mutiny.Uni<Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata>>committed(org.apache.kafka.common.TopicPartition... tps)Retrieved the last committed offset for each topic/partitionMap<String,?>configuration()Stringget(String attribute)io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>>getAssignments()Retrieves the current assignments of the consumer.io.smallrye.mutiny.Uni<Map<org.apache.kafka.common.TopicPartition,Long>>getPositions()Retrieves the next positions for each assigned topic/partitionsorg.apache.kafka.clients.consumer.ConsumerRebalanceListenergetRebalanceListener()voidinjectClient(org.apache.kafka.clients.consumer.MockConsumer<?,?> consumer)io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>>pause()Pauses the consumption of records.io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>>paused()Retrieves the set of paused topic/partitionio.smallrye.mutiny.Uni<Void>resume()Resumes the consumption of record.io.smallrye.mutiny.Uni<Void>runOnPollingThread(Consumer<org.apache.kafka.clients.consumer.Consumer<K,V>> action)Runs an action on the polling thread.<T> io.smallrye.mutiny.Uni<T>runOnPollingThread(Function<org.apache.kafka.clients.consumer.Consumer<K,V>,T> action)Runs an action on the polling thread.io.smallrye.mutiny.Uni<Void>seek(org.apache.kafka.common.TopicPartition partition, long offset)Overrides the fetch offset that the consumer will use on the next poll of given topic and partition.io.smallrye.mutiny.Uni<Void>seek(org.apache.kafka.common.TopicPartition partition, org.apache.kafka.clients.consumer.OffsetAndMetadata offsetAndMetadata)Overrides the fetch offset that the consumer will use on the next poll of given topic and partition.io.smallrye.mutiny.Uni<Void>seekToBeginning(Collection<org.apache.kafka.common.TopicPartition> partitions)Seek to the first offset for each of the given partitions.io.smallrye.mutiny.Uni<Void>seekToEnd(Collection<org.apache.kafka.common.TopicPartition> partitions)Seek to the last offset for each of the given partitions.voidsetRebalanceListener()io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>subscribe(Pattern topics)io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>subscribe(Set<String> topics)org.apache.kafka.clients.consumer.Consumer<K,V>unwrap()
-
-
-
Constructor Detail
-
ReactiveKafkaConsumer
public ReactiveKafkaConsumer(KafkaConnectorIncomingConfiguration config, KafkaSource<K,V> source)
-
-
Method Detail
-
setRebalanceListener
public void setRebalanceListener()
-
getRebalanceListener
public org.apache.kafka.clients.consumer.ConsumerRebalanceListener getRebalanceListener()
-
runOnPollingThread
public <T> io.smallrye.mutiny.Uni<T> runOnPollingThread(Function<org.apache.kafka.clients.consumer.Consumer<K,V>,T> action)
Description copied from interface:KafkaConsumerRuns an action on the polling thread.The action is a function taking as parameter the
Consumerand 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
KafkaConsumer.runOnPollingThread(java.util.function.Consumer).- Specified by:
runOnPollingThreadin interfaceKafkaConsumer<K,V>- Type Parameters:
T- 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
public io.smallrye.mutiny.Uni<Void> runOnPollingThread(Consumer<org.apache.kafka.clients.consumer.Consumer<K,V>> action)
Description copied from interface:KafkaConsumerRuns an action on the polling thread.The action is a consumer receiving the
Consumer. The producedUniemitsnullwhen the action completes. If the action throws an exception, the producedUniemits the exception as failure.- Specified by:
runOnPollingThreadin interfaceKafkaConsumer<K,V>- Parameters:
action- the action, must not benull- Returns:
- the Uni emitting
nullor the failure when the action completes.
-
pause
public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> pause()
Description copied from interface:KafkaConsumerPauses the consumption of records. The polling will continue, but no records will be received.- Specified by:
pausein interfaceKafkaConsumer<K,V>- Returns:
- the Uni emitting when the action completes, the set of topic/partition paused by this call.
-
paused
public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> paused()
Description copied from interface:KafkaConsumerRetrieves the set of paused topic/partition- Specified by:
pausedin interfaceKafkaConsumer<K,V>- Returns:
- the Uni emitting the set of topic/partition paused.
-
committed
public io.smallrye.mutiny.Uni<Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata>> committed(org.apache.kafka.common.TopicPartition... tps)
Description copied from interface:KafkaConsumerRetrieved the last committed offset for each topic/partition- Specified by:
committedin interfaceKafkaConsumer<K,V>- Parameters:
tps- the set of topic/partition to query, must not benull, must not be empty.- Returns:
- the Uni emitting the offset for the underlying consumer for each of the passed topic/partition.
-
subscribe
public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> subscribe(Set<String> topics)
-
subscribe
public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> subscribe(Pattern topics)
-
resume
public io.smallrye.mutiny.Uni<Void> resume()
Description copied from interface:KafkaConsumerResumes the consumption of record. It resumes the consumption of all the paused topic/partition.- Specified by:
resumein interfaceKafkaConsumer<K,V>- Returns:
- the Uni indicating when the resume action completes.
-
unwrap
public org.apache.kafka.clients.consumer.Consumer<K,V> unwrap()
- Specified by:
unwrapin interfaceKafkaConsumer<K,V>- Returns:
- the underlying consumer. Be aware that to use it you needs to be on the polling thread.
-
commit
public io.smallrye.mutiny.Uni<Void> commit(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> map)
Description copied from interface:KafkaConsumerCommits the offsets- Specified by:
commitin interfaceKafkaConsumer<K,V>- Parameters:
map- the map of topic/partition -> offset to commit- Returns:
- the Uni emitting
nullwhen the commit has been executed.
-
close
public void close()
-
injectClient
public void injectClient(org.apache.kafka.clients.consumer.MockConsumer<?,?> consumer)
-
getPositions
public io.smallrye.mutiny.Uni<Map<org.apache.kafka.common.TopicPartition,Long>> getPositions()
Description copied from interface:KafkaConsumerRetrieves the next positions for each assigned topic/partitions- Specified by:
getPositionsin interfaceKafkaConsumer<K,V>- Returns:
- the Uni emitting the map of topic/partition -> position.
-
getAssignments
public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> getAssignments()
Description copied from interface:KafkaConsumerRetrieves the current assignments of the consumer.- Specified by:
getAssignmentsin interfaceKafkaConsumer<K,V>- Returns:
- the Uni emitting the set of topic/partition currently assigned to the consumer
-
seek
public io.smallrye.mutiny.Uni<Void> seek(org.apache.kafka.common.TopicPartition partition, long offset)
Description copied from interface:KafkaConsumerOverrides the fetch offset that the consumer will use on the next poll of given topic and partition. Note that you may lose data if this API is arbitrarily used in the middle of consumption.- Specified by:
seekin interfaceKafkaConsumer<K,V>- Parameters:
partition- the topic and partition for which to set the offsetoffset- the new offset- Returns:
- a Uni that completes successfully when the offset is set;
it completes with
IllegalArgumentExceptionif the provided offset is negative; it completes withIllegalStateExceptionif the providedTopicPartitionis not assigned to this consumer
-
seek
public io.smallrye.mutiny.Uni<Void> seek(org.apache.kafka.common.TopicPartition partition, org.apache.kafka.clients.consumer.OffsetAndMetadata offsetAndMetadata)
Description copied from interface:KafkaConsumerOverrides the fetch offset that the consumer will use on the next poll of given topic and partition. This method allows setting the leaderEpoch along with the desired offset. Note that you may lose data if this API is arbitrarily used in the middle of consumption.- Specified by:
seekin interfaceKafkaConsumer<K,V>- Parameters:
partition- the topic and partition for which to set the offsetoffsetAndMetadata- the new offset, with additional metadata- Returns:
- a Uni that completes successfully when the offset is set;
it completes with
IllegalArgumentExceptionif the provided offset is negative; it completes withIllegalStateExceptionif the providedTopicPartitionis not assigned to this consumer
-
seekToBeginning
public io.smallrye.mutiny.Uni<Void> seekToBeginning(Collection<org.apache.kafka.common.TopicPartition> partitions)
Description copied from interface:KafkaConsumerSeek to the first offset for each of the given partitions. If no partitions are provided, seek to the first offset for all of the currently assigned partitions.- Specified by:
seekToBeginningin interfaceKafkaConsumer<K,V>- Parameters:
partitions- the partitions for which to set the offset- Returns:
- a Uni that completes successfully when the offset is set;
it completes with
IllegalArgumentExceptionifpartitionsisnull; it completes withIllegalStateExceptionif any of the providedTopicPartitions are not currently assigned to this consumer
-
seekToEnd
public io.smallrye.mutiny.Uni<Void> seekToEnd(Collection<org.apache.kafka.common.TopicPartition> partitions)
Description copied from interface:KafkaConsumerSeek to the last offset for each of the given partitions. If no partitions are provided, seek to the last offset for all of the currently assigned partitions.- Specified by:
seekToEndin interfaceKafkaConsumer<K,V>- Parameters:
partitions- the partitions for which to set the offset- Returns:
- a Uni that completes successfully when the offset is set;
it completes with
IllegalArgumentExceptionifpartitionsisnull; it completes withIllegalStateExceptionif any of the providedTopicPartitions are not currently assigned to this consumer
-
-