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 Details

  • Method Details

    • withConsumerOnPollingThread

      public io.smallrye.mutiny.Uni<org.apache.kafka.clients.consumer.Consumer<K,V>> withConsumerOnPollingThread()
    • setRebalanceListener

      public void setRebalanceListener(KafkaConsumerRebalanceListener listener, KafkaCommitHandler commitHandler)
    • setCachedConsumerGroupMetadata

      public void setCachedConsumerGroupMetadata()
    • getConsumerGroup

      public String getConsumerGroup()
    • getRebalanceListener

      public org.apache.kafka.clients.consumer.ConsumerRebalanceListener getRebalanceListener()
    • runOnPollingThread

      @CheckReturnValue public <T> io.smallrye.mutiny.Uni<T> runOnPollingThread(Function<org.apache.kafka.clients.consumer.Consumer<K,V>,T> action)
      Description copied from interface: KafkaConsumer
      Runs an action on the polling thread.

      The action is a function taking as parameter the Consumer 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 KafkaConsumer.runOnPollingThread(java.util.function.Consumer).

      Specified by:
      runOnPollingThread in interface KafkaConsumer<K,V>
      Type Parameters:
      T - 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 public io.smallrye.mutiny.Uni<Void> runOnPollingThread(Consumer<org.apache.kafka.clients.consumer.Consumer<K,V>> action)
      Description copied from interface: KafkaConsumer
      Runs an action on the polling thread.

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

      Specified by:
      runOnPollingThread in interface KafkaConsumer<K,V>
      Parameters:
      action - the action, must not be null
      Returns:
      the Uni emitting null or the failure when the action completes.
    • pause

      @CheckReturnValue public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> pause()
      Description copied from interface: KafkaConsumer
      Pauses the consumption of records. The polling will continue, but no records will be received. IMPORTANT: To use this method, you need to disable the auto-pause/resume feature from the connector. Otherwise, the client will be resumed automatically when there are enough requests. To disable the auto-pause/resume, set mp.messaging.incoming.[channel].pause-if-no-requests to false.
      Specified by:
      pause in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting when the action completes, the set of topic/partition paused by this call.
    • paused

      @CheckReturnValue public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> paused()
      Description copied from interface: KafkaConsumer
      Retrieves the set of paused topic/partition
      Specified by:
      paused in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting the set of topic/partition paused.
    • committed

      @CheckReturnValue 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: KafkaConsumer
      Retrieved the last committed offset for each topic/partition
      Specified by:
      committed in interface KafkaConsumer<K,V>
      Parameters:
      tps - the set of topic/partition to query, must not be null, must not be empty.
      Returns:
      the Uni emitting the offset for the underlying consumer for each of the passed topic/partition.
    • subscribe

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> subscribe(Set<String> topics)
    • subscribe

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> subscribe(Pattern topics)
    • assign

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> assign(Set<org.apache.kafka.common.TopicPartition> topicPartitions)
    • assignBatch

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecords<K,V>> assignBatch(Set<org.apache.kafka.common.TopicPartition> topicPartitions)
    • assignAndSeek

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> assignAndSeek(Map<org.apache.kafka.common.TopicPartition,Optional<Long>> tpOffsets)
    • assignAndSeekBatch

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecords<K,V>> assignAndSeekBatch(Map<org.apache.kafka.common.TopicPartition,Optional<Long>> tpOffsets)
    • subscribeBatch

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecords<K,V>> subscribeBatch(Set<String> topics)
    • subscribeBatch

      @CheckReturnValue public io.smallrye.mutiny.Multi<org.apache.kafka.clients.consumer.ConsumerRecords<K,V>> subscribeBatch(Pattern topics)
    • resume

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> resume()
      Description copied from interface: KafkaConsumer
      Resumes the consumption of record. It resumes the consumption of all the paused topic/partition. IMPORTANT: To use this method, you need to disable the auto-pause/resume feature from the connector. Otherwise, the client will be paused automatically when there are no requests. To disable the auto-pause/resume, set mp.messaging.incoming.[channel].pause-if-no-requests to false.
      Specified by:
      resume in interface KafkaConsumer<K,V>
      Returns:
      the Uni indicating when the resume action completes.
    • consumerGroupMetadata

      @CheckReturnValue public io.smallrye.mutiny.Uni<org.apache.kafka.clients.consumer.ConsumerGroupMetadata> consumerGroupMetadata()
      Specified by:
      consumerGroupMetadata in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting the group metadata of this consumer
    • resetToLastCommittedPositions

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> resetToLastCommittedPositions()
      Description copied from interface: KafkaConsumer
      For each assigned topic partition reset to last committed offset or the beginning
      Specified by:
      resetToLastCommittedPositions in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting null when the reset has been executed.
    • createDeserializationFailureHandler

      public static <T> DeserializationFailureHandler<T> createDeserializationFailureHandler(boolean isKey, jakarta.enterprise.inject.Instance<DeserializationFailureHandler<?>> deserializationFailureHandlers, KafkaConnectorIncomingConfiguration configuration)
    • get

      public String get(String attribute)
    • unwrap

      public org.apache.kafka.clients.consumer.Consumer<K,V> unwrap()
      Specified by:
      unwrap in interface KafkaConsumer<K,V>
      Returns:
      the underlying consumer. Be aware that to use it you needs to be on the polling thread.
    • commit

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> commit(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> map)
      Description copied from interface: KafkaConsumer
      Commits the offsets
      Specified by:
      commit in interface KafkaConsumer<K,V>
      Parameters:
      map - the map of topic/partition -> offset to commit
      Returns:
      the Uni emitting null when the commit has been executed.
    • commitAsync

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> commitAsync(Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> map)
      Description copied from interface: KafkaConsumer
      Commits the offsets asynchronously
      Specified by:
      commitAsync in interface KafkaConsumer<K,V>
      Parameters:
      map - the map of topic/partition -> offset to commit
      Returns:
      the Uni emitting null when the commit has been executed.
    • configuration

      public Map<String,?> configuration()
      Specified by:
      configuration in interface KafkaConsumer<K,V>
      Returns:
      Kafka consumer configuration
    • close

      public void close()
    • injectClient

      public void injectClient(org.apache.kafka.clients.consumer.MockConsumer<?,?> consumer)
    • getPositions

      @CheckReturnValue public io.smallrye.mutiny.Uni<Map<org.apache.kafka.common.TopicPartition,Long>> getPositions()
      Description copied from interface: KafkaConsumer
      Retrieves the next positions for each assigned topic/partitions
      Specified by:
      getPositions in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting the map of topic/partition -> position.
    • getAssignments

      @CheckReturnValue public io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> getAssignments()
      Description copied from interface: KafkaConsumer
      Retrieves the current assignments of the consumer.
      Specified by:
      getAssignments in interface KafkaConsumer<K,V>
      Returns:
      the Uni emitting the set of topic/partition currently assigned to the consumer
    • seek

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> seek(org.apache.kafka.common.TopicPartition partition, long offset)
      Description copied from interface: KafkaConsumer
      Overrides 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:
      seek in interface KafkaConsumer<K,V>
      Parameters:
      partition - the topic and partition for which to set the offset
      offset - the new offset
      Returns:
      a Uni that completes successfully when the offset is set; it completes with IllegalArgumentException if the provided offset is negative; it completes with IllegalStateException if the provided TopicPartition is not assigned to this consumer
    • seek

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> seek(org.apache.kafka.common.TopicPartition partition, org.apache.kafka.clients.consumer.OffsetAndMetadata offsetAndMetadata)
      Description copied from interface: KafkaConsumer
      Overrides 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:
      seek in interface KafkaConsumer<K,V>
      Parameters:
      partition - the topic and partition for which to set the offset
      offsetAndMetadata - the new offset, with additional metadata
      Returns:
      a Uni that completes successfully when the offset is set; it completes with IllegalArgumentException if the provided offset is negative; it completes with IllegalStateException if the provided TopicPartition is not assigned to this consumer
    • seekToBeginning

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> seekToBeginning(Collection<org.apache.kafka.common.TopicPartition> partitions)
      Description copied from interface: KafkaConsumer
      Seek 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:
      seekToBeginning in interface KafkaConsumer<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 IllegalArgumentException if partitions is null; it completes with IllegalStateException if any of the provided TopicPartitions are not currently assigned to this consumer
    • seekToEnd

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> seekToEnd(Collection<org.apache.kafka.common.TopicPartition> partitions)
      Description copied from interface: KafkaConsumer
      Seek 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:
      seekToEnd in interface KafkaConsumer<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 IllegalArgumentException if partitions is null; it completes with IllegalStateException if any of the provided TopicPartitions are not currently assigned to this consumer
    • lisTopics

      @CheckReturnValue public io.smallrye.mutiny.Uni<Map<String,List<org.apache.kafka.common.PartitionInfo>>> lisTopics()
      Specified by:
      lisTopics in interface KafkaConsumer<K,V>
    • lisTopics

      @CheckReturnValue public io.smallrye.mutiny.Uni<Map<String,List<org.apache.kafka.common.PartitionInfo>>> lisTopics(Duration timeout)
      Specified by:
      lisTopics in interface KafkaConsumer<K,V>
    • partitionsFor

      @CheckReturnValue public io.smallrye.mutiny.Uni<List<org.apache.kafka.common.PartitionInfo>> partitionsFor(String topic)
      Specified by:
      partitionsFor in interface KafkaConsumer<K,V>