Interface KafkaCluster.InteractiveConsumer<K,V>

Type Parameters:
K - the type of key
V - the type of value
All Superinterfaces:
AutoCloseable, Closeable
Enclosing class:
KafkaCluster

public static interface KafkaCluster.InteractiveConsumer<K,V> extends Closeable
A simple interactive Kafka consumer for use with the cluster.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Asynchronously close this consumer's connection to Kafka and begin to clean up all resources.
    org.apache.kafka.clients.consumer.ConsumerRecord<K,V>
    Block until a record can be read from this consumer's topic, and return the record.
    org.apache.kafka.clients.consumer.ConsumerRecord<K,V>
    nextRecord(long timeout, TimeUnit unit)
    Block until a record can be read from this consumer's topic or until the timeout occurs, and if a record was read return the record.
    default V
    Block until a record can be read from this consumer's topic, and return the value in that record.
    default V
    nextValue(long timeout, TimeUnit unit)
    Block until a record can be read from this consumer's topic or until the timeout occurs, and if a record was read return the value in that record.
    Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>
    Obtain a stream to consume the input messages.
    Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>
    Obtain a stream over all of accumulated input messages.
  • Method Details

    • nextValue

      default V nextValue() throws InterruptedException
      Block until a record can be read from this consumer's topic, and return the value in that record.
      Returns:
      the value; never null
      Throws:
      InterruptedException - if the thread is interrupted while blocking
    • nextRecord

      org.apache.kafka.clients.consumer.ConsumerRecord<K,V> nextRecord() throws InterruptedException
      Block until a record can be read from this consumer's topic, and return the record.
      Returns:
      the record; never null
      Throws:
      InterruptedException - if the thread is interrupted while blocking
    • nextValue

      default V nextValue(long timeout, TimeUnit unit) throws InterruptedException
      Block until a record can be read from this consumer's topic or until the timeout occurs, and if a record was read return the value in that record.
      Parameters:
      timeout - the maximum amount of time to block to wait for a record
      unit - the unit of time for the timeout
      Returns:
      the value, or null if the method timed out
      Throws:
      InterruptedException - if the thread is interrupted while blocking
    • nextRecord

      org.apache.kafka.clients.consumer.ConsumerRecord<K,V> nextRecord(long timeout, TimeUnit unit) throws InterruptedException
      Block until a record can be read from this consumer's topic or until the timeout occurs, and if a record was read return the record.
      Parameters:
      timeout - the maximum amount of time to block to wait for a record
      unit - the unit of time for the timeout
      Returns:
      the record, or null if the method timed out
      Throws:
      InterruptedException - if the thread is interrupted while blocking
    • stream

      Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> stream()
      Obtain a stream to consume the input messages. This method can be used in place of repeated calls to the next...() methods.
      Returns:
      the stream of all messages.
    • streamAll

      Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>> streamAll()
      Obtain a stream over all of accumulated input messages. This method can be called multiple times, and each time the resulting stream will operate over all messages that received by this consumer, and is completely independent of the stream(), nextRecord(), nextRecord(long, TimeUnit), nextValue() and nextValue(long, TimeUnit) methods.
      Returns:
      the stream of all messages.
    • close

      void close()
      Asynchronously close this consumer's connection to Kafka and begin to clean up all resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable