Class KafkaTask<T,SELF extends KafkaTask<T,SELF>>

java.lang.Object
io.smallrye.reactive.messaging.kafka.companion.KafkaTask<T,SELF>
Type Parameters:
T - the type of items
SELF - the reference to self type
All Implemented Interfaces:
AutoCloseable, Iterable<T>
Direct Known Subclasses:
ConsumerTask, ProducerTask

public abstract class KafkaTask<T,SELF extends KafkaTask<T,SELF>> extends Object implements Iterable<T>, AutoCloseable
Abstract task for consuming or producing Kafka records provided by the given Multi

This class leverages AssertSubscriber to subscribe itself to the given multi.

  • Constructor Details

    • KafkaTask

      public KafkaTask(io.smallrye.mutiny.Multi<T> multi)
      Create a new KafkaTask
      Parameters:
      multi - the multi to subscribe to
  • Method Details

    • getMulti

      public io.smallrye.mutiny.Multi<T> getMulti()
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • spliterator

      public Spliterator<T> spliterator()
      Specified by:
      spliterator in interface Iterable<T>
    • self

      protected SELF self()
    • count

      public long count()
      Returns:
      get the number of records received.
    • getFirstRecord

      public T getFirstRecord()
      Returns:
      get the first record received, potentially null if no records have been received.
    • getLastRecord

      public T getLastRecord()
      Returns:
      get the last record received, potentially null if no records have been received.
    • getRecords

      public List<T> getRecords()
      The list of items that have been received.
      Returns:
      the list
    • awaitNextRecord

      public SELF awaitNextRecord()
      Delegates to AssertSubscriber.awaitNextItem()
      Returns:
      self
    • awaitNextRecord

      public SELF awaitNextRecord(Duration duration)
      Delegates to AssertSubscriber.awaitNextItem(Duration)
      Returns:
      self
    • awaitNextRecords

      public SELF awaitNextRecords(int number)
      Delegates to AssertSubscriber.awaitNextItems(int)
      Returns:
      self
    • awaitNextRecords

      public SELF awaitNextRecords(int number, Duration duration)
      Delegates to AssertSubscriber.awaitNextItems(int, Duration)
      Returns:
      self
    • awaitRecords

      public SELF awaitRecords(int number)
      Delegates to AssertSubscriber.awaitItems(int)
      Returns:
      self
    • awaitRecords

      public SELF awaitRecords(int number, Duration duration)
      Delegates to AssertSubscriber.awaitItems(int, Duration)
      Returns:
      self
    • awaitNoRecords

      public SELF awaitNoRecords(Duration duration)
      Assert no records were received during the given duration
      Returns:
      self
    • awaitCompletion

      public SELF awaitCompletion()
      Returns:
      self
    • awaitCompletion

      public SELF awaitCompletion(Duration duration)
      Delegates to AssertSubscriber.awaitCompletion(Duration)
      Returns:
      self
    • awaitCompletion

      public SELF awaitCompletion(BiConsumer<Throwable,Boolean> assertion)
      Returns:
      self
    • awaitCompletion

      public SELF awaitCompletion(BiConsumer<Throwable,Boolean> assertion, Duration duration)
      Delegates to AssertSubscriber.awaitCompletion()
      Returns:
      self
    • stop

      public SELF stop()
      Cancels subscription effectively stopping
      Returns:
      self
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • firstOffset

      public long firstOffset()
    • lastOffset

      public long lastOffset()
    • stream

      public Stream<T> stream()
    • byTopicPartition

      public Map<org.apache.kafka.common.TopicPartition,List<T>> byTopicPartition()
    • latestOffsets

      public Map<org.apache.kafka.common.TopicPartition,Long> latestOffsets()
    • offset

      protected abstract long offset(T record)
    • topicPartition

      protected abstract org.apache.kafka.common.TopicPartition topicPartition(T record)