public interface KafkaConsumer<K,V> extends ReadStream<KafkaConsumerRecord<K,V>>
You receive Kafka records by providing a handler(Handler)
. 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(Set)
and resume(Set)
provides finer grained control over reading records
for specific Topic/Partition, these are Kafka's specific operations.
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.
|
KafkaReadStream<K,V> |
asStream() |
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(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Map<TopicPartition,Long>>> handler)
Get the first offset for the given partitions.
|
void |
beginningOffsets(TopicPartition topicPartition,
Handler<AsyncResult<Long>> handler)
Get the first offset for the given partitions.
|
default 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 |
commit(Map<TopicPartition,OffsetAndMetadata> offsets)
Commit the specified offsets for the specified list of topics and partitions to Kafka.
|
void |
commit(Map<TopicPartition,OffsetAndMetadata> offsets,
Handler<AsyncResult<Map<TopicPartition,OffsetAndMetadata>>> completionHandler)
Commit the specified offsets for the specified list of topics and partitions to Kafka.
|
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,
org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Create a new KafkaConsumer instance from a native
Consumer . |
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
|
static <K,V> KafkaConsumer<K,V> |
create(Vertx vertx,
Properties config)
Create a new KafkaConsumer instance
|
static <K,V> KafkaConsumer<K,V> |
create(Vertx vertx,
Properties 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(Set<TopicPartition> topicPartitions,
Handler<AsyncResult<Map<TopicPartition,Long>>> handler)
Get the last offset for the given partitions.
|
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<K,V> |
handler(Handler<KafkaConsumerRecord<K,V>> handler)
Set a data handler.
|
KafkaConsumer<K,V> |
listTopics(Handler<AsyncResult<Map<String,List<PartitionInfo>>>> handler)
Get metadata about partitions for all topics that the user is authorized to view.
|
void |
offsetsForTimes(Map<TopicPartition,Long> topicPartitionTimestamps,
Handler<AsyncResult<Map<TopicPartition,OffsetAndTimestamp>>> handler)
Look up the offsets for the given partitions by timestamp.
|
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.
|
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.
|
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.
|
org.apache.kafka.clients.consumer.Consumer<K,V> |
unwrap() |
static <K,V> KafkaConsumer<K,V> create(Vertx vertx, org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Consumer
.vertx
- Vert.x instance to useconsumer
- the Kafka consumer to wrapstatic <K,V> KafkaConsumer<K,V> create(Vertx vertx, Map<String,String> config)
vertx
- Vert.x instance to useconfig
- Kafka consumer configurationstatic <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 deserializationstatic <K,V> KafkaConsumer<K,V> create(Vertx vertx, Properties config)
vertx
- Vert.x instance to useconfig
- Kafka consumer configurationstatic <K,V> KafkaConsumer<K,V> create(Vertx vertx, Properties 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 deserializationKafkaConsumer<K,V> exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<KafkaConsumerRecord<K,V>>
exceptionHandler
in interface StreamBase
handler
- the exception handlerKafkaConsumer<K,V> handler(Handler<KafkaConsumerRecord<K,V>> handler)
ReadStream
handler
in interface ReadStream<KafkaConsumerRecord<K,V>>
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>>
KafkaConsumer<K,V> resume()
ReadStream
ReadSupport
has been paused, reading will recommence on it.resume
in interface ReadStream<KafkaConsumerRecord<K,V>>
KafkaConsumer<K,V> endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface ReadStream<KafkaConsumerRecord<K,V>>
KafkaConsumer<K,V> subscribe(String topic)
topic
- topic to subscribe toKafkaConsumer<K,V> subscribe(Set<String> topics)
topics
- topics to subscribe toKafkaConsumer<K,V> subscribe(String topic, Handler<AsyncResult<Void>> completionHandler)
topic
- topic to subscribe tocompletionHandler
- handler called on operation completedKafkaConsumer<K,V> subscribe(Set<String> topics, Handler<AsyncResult<Void>> completionHandler)
topics
- topics to subscribe tocompletionHandler
- handler called on operation completedKafkaConsumer<K,V> assign(TopicPartition topicPartition)
topicPartition
- partition which want assignedKafkaConsumer<K,V> assign(Set<TopicPartition> topicPartitions)
topicPartitions
- partitions which want assignedKafkaConsumer<K,V> assign(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- partition which want assignedcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> assign(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- partitions which want assignedcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> assignment(Handler<AsyncResult<Set<TopicPartition>>> handler)
handler
- handler called on operation completedKafkaConsumer<K,V> listTopics(Handler<AsyncResult<Map<String,List<PartitionInfo>>>> handler)
handler
- handler called on operation completedKafkaConsumer<K,V> unsubscribe()
KafkaConsumer<K,V> unsubscribe(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedKafkaConsumer<K,V> subscription(Handler<AsyncResult<Set<String>>> handler)
handler
- handler called on operation completedKafkaConsumer<K,V> pause(TopicPartition topicPartition)
topicPartition
- topic partition from which suspend fetchingKafkaConsumer<K,V> pause(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which suspend fetchingKafkaConsumer<K,V> pause(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition from which suspend fetchingcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> pause(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition from which suspend fetchingcompletionHandler
- handler called on operation completedvoid paused(Handler<AsyncResult<Set<TopicPartition>>> handler)
handler
- handler called on operation completedKafkaConsumer<K,V> resume(TopicPartition topicPartition)
topicPartition
- topic partition from which resume fetchingKafkaConsumer<K,V> resume(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition from which resume fetchingKafkaConsumer<K,V> resume(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition from which resume fetchingcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> resume(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition from which resume fetchingcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> partitionsRevokedHandler(Handler<Set<TopicPartition>> handler)
handler
- handler called on revoked topic partitionsKafkaConsumer<K,V> partitionsAssignedHandler(Handler<Set<TopicPartition>> handler)
handler
- handler called on assigned topic partitionsKafkaConsumer<K,V> seek(TopicPartition topicPartition, long offset)
topicPartition
- topic partition for which seekoffset
- offset to seek inside the topic partitionKafkaConsumer<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 completedKafkaConsumer<K,V> seekToBeginning(TopicPartition topicPartition)
topicPartition
- topic partition for which seekKafkaConsumer<K,V> seekToBeginning(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekKafkaConsumer<K,V> seekToBeginning(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition for which seekcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> seekToBeginning(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition for which seekcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> seekToEnd(TopicPartition topicPartition)
topicPartition
- topic partition for which seekKafkaConsumer<K,V> seekToEnd(Set<TopicPartition> topicPartitions)
topicPartitions
- topic partition for which seekKafkaConsumer<K,V> seekToEnd(TopicPartition topicPartition, Handler<AsyncResult<Void>> completionHandler)
topicPartition
- topic partition for which seekcompletionHandler
- handler called on operation completedKafkaConsumer<K,V> seekToEnd(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Void>> completionHandler)
topicPartitions
- topic partition for which seekcompletionHandler
- handler called on operation completedvoid commit()
void commit(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedvoid commit(Map<TopicPartition,OffsetAndMetadata> offsets)
offsets
- offsets list to commitvoid commit(Map<TopicPartition,OffsetAndMetadata> offsets, Handler<AsyncResult<Map<TopicPartition,OffsetAndMetadata>>> completionHandler)
offsets
- offsets list to commitcompletionHandler
- handler called on operation completedvoid committed(TopicPartition topicPartition, Handler<AsyncResult<OffsetAndMetadata>> handler)
topicPartition
- topic partition for getting last committed offsethandler
- handler called on operation completedKafkaConsumer<K,V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)
topic
- topic partition for which getting partitions infohandler
- handler called on operation completedKafkaConsumer<K,V> batchHandler(Handler<KafkaConsumerRecords<K,V>> handler)
record handler
.handler
- handler called when batches of messages are fetcheddefault void close()
void close(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedvoid position(TopicPartition partition, Handler<AsyncResult<Long>> handler)
partition
- The partition to get the position forhandler
- handler called on operation completedvoid offsetsForTimes(Map<TopicPartition,Long> topicPartitionTimestamps, Handler<AsyncResult<Map<TopicPartition,OffsetAndTimestamp>>> handler)
topicPartitionTimestamps
- A map with pairs of (TopicPartition, Timestamp).handler
- handler called on operation completedvoid 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 completedvoid beginningOffsets(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Map<TopicPartition,Long>>> handler)
topicPartitions
- the partitions to get the earliest offsets.handler
- handler called on operation completed. Returns the earliest available offsets for the given partitionsvoid 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 partitionvoid endOffsets(Set<TopicPartition> topicPartitions, Handler<AsyncResult<Map<TopicPartition,Long>>> handler)
topicPartitions
- the partitions to get the end offsets.handler
- handler called on operation completed. The end offsets for the given partitions.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.KafkaReadStream<K,V> asStream()
KafkaReadStream
instanceCopyright © 2017. All rights reserved.