【发布时间】:2019-05-13 14:18:51
【问题描述】:
我正在尝试通过@KafkaListener 阅读压缩主题。 我希望每个消费者每次都阅读整个主题。
我无法为每个消费者生成一个唯一的 groupId。所以我想使用一个空 groupid。
我已尝试配置容器和消费者以将 groupId 设置为 null,但均未成功。
这是我的容器配置:
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
configurer.configure(factory, kafkaConsumerFactory);
// Set ackMode to manual and never commit, we are reading from the beginning each time
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL);
factory.getContainerProperties().setAckOnError(false);
// Remove groupId, we are consuming all partitions here
factory.getContainerProperties().setGroupId(null);
// Enable idle event in order to detect when init phase is over
factory.getContainerProperties().setIdleEventInterval(1000L);
还尝试强制消费者配置:
Map<String, Object> consumerProperties = sprinfKafkaProperties.buildConsumerProperties();
// Override group id property to force "null"
consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, null);
ConsumerFactory<Object, Object> kafkaConsumerFactory = new DefaultKafkaConsumerFactory<>(consumerProperties);
当我将容器 groupId 设置为 null 时,使用带有侦听器 ID 的默认值。
当我强制消费者使用 null groupId 属性时,出现错误: 在消费者配置、容器属性或@KafkaListener 注释中找不到 group.id;使用组管理时需要 group.id。
【问题讨论】: