【发布时间】:2021-11-03 00:52:01
【问题描述】:
我正在使用ContainerProperties 创建一个新的KafkaMessageListenerContainer。
-
使用
ContainerProperties(String... topics),消费者组看起来不错:"state": "STABLE", "isSimpleConsumerGroup": false -
使用
ContainerProperties(TopicPartitionOffset... topicPartitions),不会自动创建消费者组。最终在发送消息时创建,但 Consumer Group 看起来不太好:"state": "EMPTY", "isSimpleConsumerGroup": true
他们之间有什么区别,我错过了什么。我希望使用两个不同的 ContainerProperties 构造函数得到相同的结果。
ContainerProperties containerProps = new ContainerProperties(tpo.toArray(new TopicPartitionOffset[tpo.size()]));
containerProps.setGroupId(name);
// ContainerProperties containerProps = new ContainerProperties("poc-topic1",
// "poc-topic2", "poc-topic3");
// containerProps.setGroupId(name);
containerProps.setMessageListener(new TopicMessageListener(name));
DefaultKafkaConsumerFactory<String, Serializable> factory = new DefaultKafkaConsumerFactory<>(
Utils.get().getConsumerProperties());
container = new KafkaMessageListenerContainer<>(factory, containerProps);
// container.setAutoStartup(true);
// container.setBeanName(name);
// container.checkGroupId();
container.start();
【问题讨论】: