public class KafkaConsumer<K,V> extends Object implements ReadStream<KafkaConsumerRecord<K,V>>
You receive Kafka records by providing a handler(io.vertx.core.Handler<io.vertx.reactivex.kafka.client.consumer.KafkaConsumerRecord<K, V>>)
. As messages arrive the handler
will be called with the records.
The pause()
and resume()
provides global control over reading the records from the consumer.
The pause()
and resume()
provides finer grained control over reading records
for specific Topic/Partition, these are Kafka's specific operations.
original
non RX-ified interface using Vert.x codegen.Modifier and Type | Field and Description |
---|---|
static TypeArg<KafkaConsumer> |
__TYPE_ARG |
TypeArg<K> |
__typeArg_0 |
TypeArg<V> |
__typeArg_1 |
Constructor and Description |
---|
KafkaConsumer(KafkaConsumer delegate) |
KafkaConsumer(KafkaConsumer delegate,
TypeArg<K> typeArg_0,
TypeArg<V> typeArg_1) |
Modifier and Type | Method and Description |
---|---|
KafkaConsumer<K,V> |
assign(Set<TopicPartition> topicPartitions)
Manually assign a list of partition to this consumer.
|
KafkaConsumer<K,V> |
assign(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Void>> completionHandler)
Manually assign a list of partition to this consumer.
|
KafkaConsumer<K,V> |
assign(TopicPartition topicPartition)
Manually assign a partition to this consumer.
|
KafkaConsumer<K,V> |
assign(TopicPartition topicPartition,
Handler<AsyncResult<Void>> completionHandler)
Manually assign a partition to this consumer.
|
KafkaConsumer<K,V> |
assignment(Handler<AsyncResult<Set<TopicPartition>>> handler)
Get the set of partitions currently assigned to this consumer.
|
KafkaConsumer<K,V> |
batchHandler(Handler<KafkaConsumerRecords<K,V>> handler)
Set the handler to be used when batches of messages are fetched
from the Kafka server.
|
void |
beginningOffsets(TopicPartition topicPartition,
Handler<AsyncResult<Long>> handler)
Get the first offset for the given partitions.
|
void |
close()
Close the consumer
|
void |
close(Handler<AsyncResult<Void>> completionHandler)
Close the consumer
|
void |
commit()
Commit current offsets for all the subscribed list of topics and partition.
|
void |
commit(Handler<AsyncResult<Void>> completionHandler)
Commit current offsets for all the subscribed list of topics and partition.
|
void |
committed(TopicPartition topicPartition,
Handler<AsyncResult<OffsetAndMetadata>> handler)
Get the last committed offset for the given partition (whether the commit happened by this process or another).
|
static <K,V> KafkaConsumer<K,V> |
create(Vertx vertx,
Map<String,String> config)
Create a new KafkaConsumer instance
|
static <K,V> KafkaConsumer<K,V> |
create(Vertx vertx,
Map<String,String> config,
Class<K> keyType,
Class<V> valueType)
Create a new KafkaConsumer instance
|
KafkaConsumer<K,V> |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
void |
endOffsets(TopicPartition topicPartition,
Handler<AsyncResult<Long>> handler)
Get the last offset for the given partition.
|
KafkaConsumer<K,V> |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
KafkaConsumer |
getDelegate() |
KafkaConsumer<K,V> |
handler(Handler<KafkaConsumerRecord<K,V>> handler)
Set a data handler.
|
static <K,V> KafkaConsumer<K,V> |
newInstance(KafkaConsumer arg) |
static <K,V> KafkaConsumer<K,V> |
newInstance(KafkaConsumer arg,
TypeArg<K> __typeArg_K,
TypeArg<V> __typeArg_V) |
void |
offsetsForTimes(TopicPartition topicPartition,
Long timestamp,
Handler<AsyncResult<OffsetAndTimestamp>> handler)
Look up the offset for the given partition by timestamp.
|
KafkaConsumer<K,V> |
partitionsAssignedHandler(Handler<Set<TopicPartition>> handler)
Set the handler called when topic partitions are assigned to the consumer
|
KafkaConsumer<K,V> |
partitionsFor(String topic,
Handler<AsyncResult<List<PartitionInfo>>> handler)
Get metadata about the partitions for a given topic.
|
KafkaConsumer<K,V> |
partitionsRevokedHandler(Handler<Set<TopicPartition>> handler)
Set the handler called when topic partitions are revoked to the consumer
|
KafkaConsumer<K,V> |
pause()
Pause the
ReadSupport . |
KafkaConsumer<K,V> |
pause(Set<TopicPartition> topicPartitions)
Suspend fetching from the requested partitions.
|
KafkaConsumer<K,V> |
pause(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Void>> completionHandler)
Suspend fetching from the requested partitions.
|
KafkaConsumer<K,V> |
pause(TopicPartition topicPartition)
Suspend fetching from the requested partition.
|
KafkaConsumer<K,V> |
pause(TopicPartition topicPartition,
Handler<AsyncResult<Void>> completionHandler)
Suspend fetching from the requested partition.
|
void |
paused(Handler<AsyncResult<Set<TopicPartition>>> handler)
Get the set of partitions that were previously paused by a call to pause(Set).
|
void |
position(TopicPartition partition,
Handler<AsyncResult<Long>> handler)
Get the offset of the next record that will be fetched (if a record with that offset exists).
|
KafkaConsumer<K,V> |
resume()
Resume reading.
|
KafkaConsumer<K,V> |
resume(Set<TopicPartition> topicPartitions)
Resume specified partitions which have been paused with pause.
|
KafkaConsumer<K,V> |
resume(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Void>> completionHandler)
Resume specified partitions which have been paused with pause.
|
KafkaConsumer<K,V> |
resume(TopicPartition topicPartition)
Resume specified partition which have been paused with pause.
|
KafkaConsumer<K,V> |
resume(TopicPartition topicPartition,
Handler<AsyncResult<Void>> completionHandler)
Resume specified partition which have been paused with pause.
|
Completable |
rxAssign(Set<TopicPartition> topicPartitions)
Manually assign a list of partition to this consumer.
|
Completable |
rxAssign(TopicPartition topicPartition)
Manually assign a partition to this consumer.
|
Single<Set<TopicPartition>> |
rxAssignment()
Get the set of partitions currently assigned to this consumer.
|
Single<Long> |
rxBeginningOffsets(TopicPartition topicPartition)
Get the first offset for the given partitions.
|
Completable |
rxClose()
Close the consumer
|
Completable |
rxCommit()
Commit current offsets for all the subscribed list of topics and partition.
|
Single<OffsetAndMetadata> |
rxCommitted(TopicPartition topicPartition)
Get the last committed offset for the given partition (whether the commit happened by this process or another).
|
Single<Long> |
rxEndOffsets(TopicPartition topicPartition)
Get the last offset for the given partition.
|
Single<OffsetAndTimestamp> |
rxOffsetsForTimes(TopicPartition topicPartition,
Long timestamp)
Look up the offset for the given partition by timestamp.
|
Single<List<PartitionInfo>> |
rxPartitionsFor(String topic)
Get metadata about the partitions for a given topic.
|
Completable |
rxPause(Set<TopicPartition> topicPartitions)
Suspend fetching from the requested partitions.
|
Completable |
rxPause(TopicPartition topicPartition)
Suspend fetching from the requested partition.
|
Single<Set<TopicPartition>> |
rxPaused()
Get the set of partitions that were previously paused by a call to pause(Set).
|
Single<Long> |
rxPosition(TopicPartition partition)
Get the offset of the next record that will be fetched (if a record with that offset exists).
|
Completable |
rxResume(Set<TopicPartition> topicPartitions)
Resume specified partitions which have been paused with pause.
|
Completable |
rxResume(TopicPartition topicPartition)
Resume specified partition which have been paused with pause.
|
Completable |
rxSeek(TopicPartition topicPartition,
long offset)
Overrides the fetch offsets that the consumer will use on the next poll.
|
Completable |
rxSeekToBeginning(Set<TopicPartition> topicPartitions)
Seek to the first offset for each of the given partitions.
|
Completable |
rxSeekToBeginning(TopicPartition topicPartition)
Seek to the first offset for each of the given partition.
|
Completable |
rxSeekToEnd(Set<TopicPartition> topicPartitions)
Seek to the last offset for each of the given partitions.
|
Completable |
rxSeekToEnd(TopicPartition topicPartition)
Seek to the last offset for each of the given partition.
|
Completable |
rxSubscribe(Set<String> topics)
Subscribe to the given list of topics to get dynamically assigned partitions.
|
Completable |
rxSubscribe(String topic)
Subscribe to the given topic to get dynamically assigned partitions.
|
Single<Set<String>> |
rxSubscription()
Get the current subscription.
|
Completable |
rxUnsubscribe()
Unsubscribe from topics currently subscribed with subscribe.
|
KafkaConsumer<K,V> |
seek(TopicPartition topicPartition,
long offset)
Overrides the fetch offsets that the consumer will use on the next poll.
|
KafkaConsumer<K,V> |
seek(TopicPartition topicPartition,
long offset,
Handler<AsyncResult<Void>> completionHandler)
Overrides the fetch offsets that the consumer will use on the next poll.
|
KafkaConsumer<K,V> |
seekToBeginning(Set<TopicPartition> topicPartitions)
Seek to the first offset for each of the given partitions.
|
KafkaConsumer<K,V> |
seekToBeginning(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Void>> completionHandler)
Seek to the first offset for each of the given partitions.
|
KafkaConsumer<K,V> |
seekToBeginning(TopicPartition topicPartition)
Seek to the first offset for each of the given partition.
|
KafkaConsumer<K,V> |
seekToBeginning(TopicPartition topicPartition,
Handler<AsyncResult<Void>> completionHandler)
Seek to the first offset for each of the given partition.
|
KafkaConsumer<K,V> |
seekToEnd(Set<TopicPartition> topicPartitions)
Seek to the last offset for each of the given partitions.
|
KafkaConsumer<K,V> |
seekToEnd(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Void>> completionHandler)
Seek to the last offset for each of the given partitions.
|
KafkaConsumer<K,V> |
seekToEnd(TopicPartition topicPartition)
Seek to the last offset for each of the given partition.
|
KafkaConsumer<K,V> |
seekToEnd(TopicPartition topicPartition,
Handler<AsyncResult<Void>> completionHandler)
Seek to the last offset for each of the given partition.
|
KafkaConsumer<K,V> |
subscribe(Set<String> topics)
Subscribe to the given list of topics to get dynamically assigned partitions.
|
KafkaConsumer<K,V> |
subscribe(Set<String> topics,
Handler<AsyncResult<Void>> completionHandler)
Subscribe to the given list of topics to get dynamically assigned partitions.
|
KafkaConsumer<K,V> |
subscribe(String topic)
Subscribe to the given topic to get dynamically assigned partitions.
|
KafkaConsumer<K,V> |
subscribe(String topic,
Handler<AsyncResult<Void>> completionHandler)
Subscribe to the given topic to get dynamically assigned partitions.
|
KafkaConsumer<K,V> |
subscription(Handler<AsyncResult<Set<String>>> handler)
Get the current subscription.
|
Flowable<KafkaConsumerRecord<K,V>> |
toFlowable() |
Observable<KafkaConsumerRecord<K,V>> |
toObservable() |
KafkaConsumer<K,V> |
unsubscribe()
Unsubscribe from topics currently subscribed with subscribe.
|
KafkaConsumer<K,V> |
unsubscribe(Handler<AsyncResult<Void>> completionHandler)
Unsubscribe from topics currently subscribed with subscribe.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
newInstance, newInstance
newInstance
public static final TypeArg<KafkaConsumer> __TYPE_ARG
public KafkaConsumer(KafkaConsumer delegate)
public KafkaConsumer(KafkaConsumer delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
public KafkaConsumer getDelegate()
getDelegate
in interface ReadStream<KafkaConsumerRecord<K,V>>
getDelegate
in interface StreamBase
public Observable<KafkaConsumerRecord<K,V>> toObservable()
toObservable
in interface ReadStream<KafkaConsumerRecord<K,V>>
public Flowable<KafkaConsumerRecord<K,V>> toFlowable()
toFlowable
in interface ReadStream<KafkaConsumerRecord<K,V>>
public static <K,V> KafkaConsumer<K,V> create(Vertx vertx, Map<String,String> config)
vertx
- Vert.x instance to useconfig
- Kafka consumer configurationpublic static <K,V> KafkaConsumer<K,V> create(Vertx vertx, Map<String,String> config, Class<K> keyType, Class<V> valueType)
vertx
- Vert.x instance to useconfig
- Kafka consumer configurationkeyType
- class type for the key deserializationvalueType
- class type for the value deserializationpublic KafkaConsumer<K,V> exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<KafkaConsumerRecord<K,V>>
exceptionHandler
in interface StreamBase
handler
- the exception handlerpublic KafkaConsumer<K,V> handler(Handler<KafkaConsumerRecord<K,V>> handler)
ReadStream
handler
in interface ReadStream<KafkaConsumerRecord<K,V>>
public KafkaConsumer<K,V> pause()
ReadStream
ReadSupport
. While it's paused, no data will be sent to the dataHandler
pause
in interface ReadStream<KafkaConsumerRecord<K,V>>
public KafkaConsumer<K,V> resume()
ReadStream
ReadSupport
has been paused, reading will recommence on it.resume
in interface ReadStream<KafkaConsumerRecord<K,V>>
public KafkaConsumer<K,V> endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface ReadStream<KafkaConsumerRecord<K,V>>
public KafkaConsumer<K,V> subscribe(String topic)
topic
- topic to subscribe topublic KafkaConsumer<K,V> subscribe(Set<String> topics)
topics
- topics to subscribe topublic KafkaConsumer<K,V> subscribe(String topic, Handler<AsyncResult<Void>> completionHandler)
topic
- topic to subscribe tocompletionHandler
- handler called on operation completedpublic Completable rxSubscribe(String topic)
topic
- topic to subscribe topublic KafkaConsumer<K,V> subscribe(Set<String> topics, Handler<AsyncResult<Void>> completionHandler)
topics
- topics to subscribe tocompletionHandler
- handler called on operation completedpublic Completable rxSubscribe(Set<String> topics)
topics
- topics to subscribe topublic KafkaConsumer<K,V> assign(TopicPartition topicPartition)
topicPartition
- partition which want assignedpublic KafkaConsumer<K,V> assign(Set<TopicPartition> topicPartitions)
topicPartitions
- partitions which want assignedpublic KafkaConsumer<K,V> assign(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- partition which want assignedcompletionHandler
- handler called on operation completedpublic Completable rxAssign(TopicPartition topicPartition)
topicPartition
- partition which want assignedpublic KafkaConsumer<K,V> assign(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- partitions which want assignedcompletionHandler
- handler called on operation completedpublic Completable rxAssign(Set<TopicPartition> topicPartitions)
topicPartitions
- partitions which want assignedpublic KafkaConsumer<K,V> assignment(Handler<AsyncResult<Set<TopicPartition>>> handler)
handler
- handler called on operation completedpublic Single<Set<TopicPartition>> rxAssignment()
public KafkaConsumer<K,V> unsubscribe()
public KafkaConsumer<K,V> unsubscribe(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedpublic Completable rxUnsubscribe()
public KafkaConsumer<K,V> subscription(Handler<AsyncResult<Set<String>>> handler)
handler
- handler called on operation completedpublic KafkaConsumer<K,V> pause(TopicPartition topicPartition)
topicPartition
- topic partition from which suspend fetchingpublic KafkaConsumer<K,V> pause(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which suspend fetchingpublic KafkaConsumer<K,V> pause(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition from which suspend fetchingcompletionHandler
- handler called on operation completedpublic Completable rxPause(TopicPartition topicPartition)
topicPartition
- topic partition from which suspend fetchingpublic KafkaConsumer<K,V> pause(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition from which suspend fetchingcompletionHandler
- handler called on operation completedpublic Completable rxPause(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which suspend fetchingpublic void paused(Handler<AsyncResult<Set<TopicPartition>>> handler)
handler
- handler called on operation completedpublic Single<Set<TopicPartition>> rxPaused()
public KafkaConsumer<K,V> resume(TopicPartition topicPartition)
topicPartition
- topic partition from which resume fetchingpublic KafkaConsumer<K,V> resume(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which resume fetchingpublic KafkaConsumer<K,V> resume(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition from which resume fetchingcompletionHandler
- handler called on operation completedpublic Completable rxResume(TopicPartition topicPartition)
topicPartition
- topic partition from which resume fetchingpublic KafkaConsumer<K,V> resume(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition from which resume fetchingcompletionHandler
- handler called on operation completedpublic Completable rxResume(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which resume fetchingpublic KafkaConsumer<K,V> partitionsRevokedHandler(Handler<Set<TopicPartition>> handler)
handler
- handler called on revoked topic partitionspublic KafkaConsumer<K,V> partitionsAssignedHandler(Handler<Set<TopicPartition>> handler)
handler
- handler called on assigned topic partitionspublic KafkaConsumer<K,V> seek(TopicPartition topicPartition, long offset)
topicPartition
- topic partition for which seekoffset
- offset to seek inside the topic partitionpublic KafkaConsumer<K,V> seek(TopicPartition topicPartition, long offset, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition for which seekoffset
- offset to seek inside the topic partitioncompletionHandler
- handler called on operation completedpublic Completable rxSeek(TopicPartition topicPartition, long offset)
topicPartition
- topic partition for which seekoffset
- offset to seek inside the topic partitionpublic KafkaConsumer<K,V> seekToBeginning(TopicPartition topicPartition)
topicPartition
- topic partition for which seekpublic KafkaConsumer<K,V> seekToBeginning(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekpublic KafkaConsumer<K,V> seekToBeginning(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition for which seekcompletionHandler
- handler called on operation completedpublic Completable rxSeekToBeginning(TopicPartition topicPartition)
topicPartition
- topic partition for which seekpublic KafkaConsumer<K,V> seekToBeginning(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition for which seekcompletionHandler
- handler called on operation completedpublic Completable rxSeekToBeginning(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekpublic KafkaConsumer<K,V> seekToEnd(TopicPartition topicPartition)
topicPartition
- topic partition for which seekpublic KafkaConsumer<K,V> seekToEnd(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekpublic KafkaConsumer<K,V> seekToEnd(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition for which seekcompletionHandler
- handler called on operation completedpublic Completable rxSeekToEnd(TopicPartition topicPartition)
topicPartition
- topic partition for which seekpublic KafkaConsumer<K,V> seekToEnd(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition for which seekcompletionHandler
- handler called on operation completedpublic Completable rxSeekToEnd(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekpublic void commit()
public void commit(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedpublic Completable rxCommit()
public void committed(TopicPartition topicPartition, Handler<AsyncResult<OffsetAndMetadata>> handler)
topicPartition
- topic partition for getting last committed offsethandler
- handler called on operation completedpublic Single<OffsetAndMetadata> rxCommitted(TopicPartition topicPartition)
topicPartition
- topic partition for getting last committed offsetpublic KafkaConsumer<K,V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)
topic
- topic partition for which getting partitions infohandler
- handler called on operation completedpublic Single<List<PartitionInfo>> rxPartitionsFor(String topic)
topic
- topic partition for which getting partitions infopublic KafkaConsumer<K,V> batchHandler(Handler<KafkaConsumerRecords<K,V>> handler)
#handler(Handler) record handler
.handler
- handler called when batches of messages are fetchedpublic void close()
public void close(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedpublic Completable rxClose()
public void position(TopicPartition partition, Handler<AsyncResult<Long>> handler)
partition
- The partition to get the position forhandler
- handler called on operation completedpublic Single<Long> rxPosition(TopicPartition partition)
partition
- The partition to get the position forpublic void offsetsForTimes(TopicPartition topicPartition, Long timestamp, Handler<AsyncResult<OffsetAndTimestamp>> handler)
topicPartition
- TopicPartition to query.timestamp
- Timestamp to be used in the query.handler
- handler called on operation completedpublic Single<OffsetAndTimestamp> rxOffsetsForTimes(TopicPartition topicPartition, Long timestamp)
topicPartition
- TopicPartition to query.timestamp
- Timestamp to be used in the query.public void beginningOffsets(TopicPartition topicPartition, Handler<AsyncResult<Long>> handler)
topicPartition
- the partition to get the earliest offset.handler
- handler called on operation completed. Returns the earliest available offset for the given partitionpublic Single<Long> rxBeginningOffsets(TopicPartition topicPartition)
topicPartition
- the partition to get the earliest offset.public void endOffsets(TopicPartition topicPartition, Handler<AsyncResult<Long>> handler)
topicPartition
- the partition to get the end offset.handler
- handler called on operation completed. The end offset for the given partition.public Single<Long> rxEndOffsets(TopicPartition topicPartition)
topicPartition
- the partition to get the end offset.public static <K,V> KafkaConsumer<K,V> newInstance(KafkaConsumer arg)
public static <K,V> KafkaConsumer<K,V> newInstance(KafkaConsumer arg, TypeArg<K> __typeArg_K, TypeArg<V> __typeArg_V)
Copyright © 2017. All rights reserved.