gpt4 book ai didi

apache-kafka - 0.11.0.1 上的 KAFKA 组协调器故障恢复

转载 作者:行者123 更新时间:2023-12-02 17:15:03 28 4
gpt4 key购买 nike

是否有任何配置可以在崩溃后启用自动组协调器恢复?

我有一个包含 3 个代理的测试拓扑,一旦组协调器关闭,主题分区(rf=2 的 2 个分区)正确地重新平衡,生产者不受影响,但消费者组停止接收消息。如果我选择任何其他经纪人,一切都会按预期进行。

为生产者和客户端使用 JAVA API Kafka 客户端 0.10.2.1

<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.10.2.1</version>
</dependency>

监控每个仍在运行的代理的控制台输出,我没有找到任何新的 GroupCoordinator 分配的引用。我启动原始组协调器代理后,所有消费者都会恢复接收消息。被选为协调器的 broker 始终是 broker.id=0,无论启动顺序如何。

客户端配置:

private static Consumer<String, String> createFixMessageConsumer(int id) {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092,localhost:9093,localhost:9094");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "1000");
props.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "6100");
props.put(ConsumerConfig.GROUP_ID_CONFIG, MYCONSUMERGROUP);
props.put(ConsumerConfig.CLIENT_ID_CONFIG, id + "");
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
return new KafkaConsumer<>(props, new StringDeserializer(), new FixMessageDeserializer());
}

Consumer Worker 片段:

    @Override
public void run() {
try {
consumer.subscribe(topics);

while (true) {
ConsumerRecords<String, FixMessage> records = consumer.poll(2000);
FixMessage message = null;
for (ConsumerRecord<String, FixMessage> record : records) {
message = record.value();
message.setConsumerId(id);
message.setKafkaPartition(record.partition());
message.setPartitionOffset(BigInteger.valueOf(record.offset()));
Map<String, Object> data = new HashMap<>();
data.put("partition", record.partition());
data.put("offset", record.offset());
if(message.getIdfixMessage() == null)
createFixMessage(message, data);
data.put("value", message.getIdfixMessage());
System.out.println(this.id + ": " + data);
}
}
} catch (WakeupException e) {
// ignore for shutdown
} catch(Exception e) {
System.out.println(e.toString());
} finally {
consumer.close();
}
}

最佳答案

确保主题 __consumer_offsets 的复制因子在您的情况下大于 1。 0.11.0.0之前,broker端参数default.replication.factor不会强制执行,所以很有可能这个内部topic的rf小于default.replication.factor 你设置。

关于apache-kafka - 0.11.0.1 上的 KAFKA 组协调器故障恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46817599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com