K - the type of key for records consumed from KafkaV - the type of value for records consumed from Kafkapublic final class LcKafkaConsumer<K,V> extends Object implements Closeable
LcKafkaConsumer is a wrapper over Consumer. It will use Consumer to consume
records from Kafka broker.
With LcKafkaConsumer, you can subscribe to several topics and handle all the records from these topics
in a dedicated thread pool without warring polling timeout or session timeout due to the polling thread spend
too much time on process records and failed to poll broker at least once within max.poll.interval.ms.
All the public methods in LcKafkaConsumer is thread safe.
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> |
metrics()
Get the metrics kept by the consumer
|
CompletableFuture<UnsubscribedStatus> |
subscribe(Collection<String> topics)
Subscribe some Kafka topics to consume records from them.
|
CompletableFuture<UnsubscribedStatus> |
subscribe(Pattern pattern)
Subscribe to all topics matching specified pattern to get dynamically assigned partitions.
|
public CompletableFuture<UnsubscribedStatus> subscribe(Collection<String> topics)
topics - the topics to consume.CompletableFuture which will be complete when the internal
KafkaConsumer unsubscribed all the topics that have subscribed to
due to an error occurred or close() was called. If it is due to an error occurred, this
LcKafkaConsumer will be closed before the returned CompletableFuture complete.IllegalStateException - if this LcKafkaConsumer has closed or subscribed to some topicsNullPointerException - if the input topics is nullIllegalArgumentException - if the input topics is empty or contains null or empty topicpublic CompletableFuture<UnsubscribedStatus> subscribe(Pattern pattern)
metadata.max.age.ms configuration: by lowering
the max metadata age, the consumer will refresh metadata more often and check for matching topics.pattern - Pattern to subscribe to.CompletableFuture which will be complete when the internal
KafkaConsumer unsubscribed all the topics that have subscribed to
due to an error occurred or close() was called. If it is due to an error occurred, this
LcKafkaConsumer will be closed before the returned CompletableFuture complete.IllegalStateException - if this LcKafkaConsumer has closed or subscribed to some topicsNullPointerException - if the input pattern is nullpublic Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric> metrics()
public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2020 LeanCloud. All rights reserved.