Class KafkaTask<T,​SELF extends 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 Detail

      • KafkaTask

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

      • getMulti

        public io.smallrye.mutiny.Multi<T> getMulti()
      • 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
      • stop

        public SELF stop()
        Cancels subscription effectively stopping
        Returns:
        self
      • 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)