public class KafkaConsumer extends Object implements Consumer
| Constructor and Description |
|---|
KafkaConsumer(org.apache.kafka.clients.consumer.Consumer<String,byte[]> consumer)
构造
|
KafkaConsumer(Properties properties)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
KafkaConsumer |
setTopicPattern(Pattern topicPattern)
设置消费的topic正则
|
KafkaConsumer |
setTopics(String... topics)
设置消费的topic
|
void |
subscribe(MessageHandler messageHandler)
单次订阅消息
|
public KafkaConsumer(Properties properties)
properties - 配置public KafkaConsumer(org.apache.kafka.clients.consumer.Consumer<String,byte[]> consumer)
consumer - Consumerpublic KafkaConsumer setTopics(String... topics)
topics - topicpublic KafkaConsumer setTopicPattern(Pattern topicPattern)
topicPattern - topicPatternpublic void subscribe(MessageHandler messageHandler)
Consumerpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2025. All rights reserved.