我想有一个消费者池,并重用每个消费者。对吗?
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...
或者我应该在每次需要时创建新的消费者?
暂无答案!
目前还没有任何答案,快来回答吧!