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 itemsSELF- 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 givenMultiThis class leverages
AssertSubscriberto subscribe itself to the given multi.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SELFawaitCompletion()SELFawaitCompletion(Duration duration)Delegates toAssertSubscriber.awaitCompletion(Duration)SELFawaitCompletion(BiConsumer<Throwable,Boolean> assertion)SELFawaitCompletion(BiConsumer<Throwable,Boolean> assertion, Duration duration)Delegates toAssertSubscriber.awaitCompletion()SELFawaitNextRecord()Delegates toAssertSubscriber.awaitNextItem()SELFawaitNextRecord(Duration duration)Delegates toAssertSubscriber.awaitNextItem(Duration)SELFawaitNextRecords(int number)Delegates toAssertSubscriber.awaitNextItems(int)SELFawaitNextRecords(int number, Duration duration)Delegates toAssertSubscriber.awaitNextItems(int, Duration)SELFawaitNoRecords(Duration duration)Assert no records were received during the given durationSELFawaitRecords(int number)Delegates toAssertSubscriber.awaitItems(int)SELFawaitRecords(int number, Duration duration)Delegates toAssertSubscriber.awaitItems(int, Duration)Map<org.apache.kafka.common.TopicPartition,List<T>>byTopicPartition()voidclose()longcount()longfirstOffset()TgetFirstRecord()TgetLastRecord()io.smallrye.mutiny.Multi<T>getMulti()List<T>getRecords()The list of items that have been received.Iterator<T>iterator()longlastOffset()Map<org.apache.kafka.common.TopicPartition,Long>latestOffsets()protected abstract longoffset(T record)protected SELFself()Spliterator<T>spliterator()SELFstop()Cancels subscription effectively stoppingStream<T>stream()protected abstract org.apache.kafka.common.TopicPartitiontopicPartition(T record)
-
-
-
Method Detail
-
getMulti
public io.smallrye.mutiny.Multi<T> getMulti()
-
spliterator
public Spliterator<T> spliterator()
- Specified by:
spliteratorin interfaceIterable<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
nullif no records have been received.
-
getLastRecord
public T getLastRecord()
- Returns:
- get the last record received, potentially
nullif no records have been received.
-
awaitNextRecord
public SELF awaitNextRecord()
Delegates toAssertSubscriber.awaitNextItem()- Returns:
- self
-
awaitNextRecord
public SELF awaitNextRecord(Duration duration)
Delegates toAssertSubscriber.awaitNextItem(Duration)- Returns:
- self
-
awaitNextRecords
public SELF awaitNextRecords(int number)
Delegates toAssertSubscriber.awaitNextItems(int)- Returns:
- self
-
awaitNextRecords
public SELF awaitNextRecords(int number, Duration duration)
Delegates toAssertSubscriber.awaitNextItems(int, Duration)- Returns:
- self
-
awaitRecords
public SELF awaitRecords(int number)
Delegates toAssertSubscriber.awaitItems(int)- Returns:
- self
-
awaitRecords
public SELF awaitRecords(int number, Duration duration)
Delegates toAssertSubscriber.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 toAssertSubscriber.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 toAssertSubscriber.awaitCompletion()- Returns:
- self
-
stop
public SELF stop()
Cancels subscription effectively stopping- Returns:
- self
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
firstOffset
public long firstOffset()
-
lastOffset
public long lastOffset()
-
offset
protected abstract long offset(T record)
-
topicPartition
protected abstract org.apache.kafka.common.TopicPartition topicPartition(T record)
-
-