Package io.debezium.kafka
Interface KafkaCluster.InteractiveConsumer<K,V>
-
- Type Parameters:
K- the type of keyV- 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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Asynchronously close this consumer's connection to Kafka and begin to clean up all resources.org.apache.kafka.clients.consumer.ConsumerRecord<K,V>nextRecord()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 VnextValue()Block until a record can be read from this consumer's topic, and return the value in that record.default VnextValue(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>>stream()Obtain a stream to consume the input messages.Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>streamAll()Obtain a stream over all of accumulated input messages.
-
-
-
Method Detail
-
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 recordunit- the unit of time for thetimeout- 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 recordunit- the unit of time for thetimeout- 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 thenext...()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 thestream(),nextRecord(),nextRecord(long, TimeUnit),nextValue()andnextValue(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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-