我可以重用java kafka消费者吗?

a9wyjsp7  于 2021-06-06  发布在  Kafka
关注(0)|答案(0)|浏览(205)

我想有一个消费者池,并重用每个消费者。对吗?

KafkaConsumer consumer = createConsumer();
TopicPartition topicPartition = new TopicPartition("topic", 2);
consumer.assign(List.of(topicPartition));
consumer.seek(topicPartition, 41);

ConsumerRecords records = consumer.poll(0);
// use records...

// reuse kafka consumer 
consumer.unsubscribe();

topicPartition = new TopicPartition("topic", 1);
consumer.assign(List.of(topicPartition));
consumer.seek(topicPartition, 8);

records = consumer.poll(0);
// use records...

或者我应该在每次需要时创建新的消费者?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题