gpt4 book ai didi

apache-kafka - 卡夫卡生产者抛出错误尝试从状态 IN_TRANSACTION 到状态 IN_TRANSACTION 的无效转换

转载 作者:行者123 更新时间:2023-12-03 17:26:59 25 4
gpt4 key购买 nike

我的 kafka 生产者抛出错误“尝试从状态 IN_TRANSACTION 到状态 IN_TRANSACTION 的无效转换”。这是我正在努力实现的目标 -

KafkaProducer producer = new KafkaProducer<>(props);
producer.initTransactions();
//transaction 1
producer.beginTransaction();
//send some messages
producer.commitTransaction();

//transaction 2
producer.beginTransaction(); //here it throws an exception "Invalid transition attempted from state IN_TRANSACTION to state IN_TRANSACTION".
//send some messages
producer.commitTransaction();

producer.close();
如果我打电话 producer.initTransactions();在开始事务 2 之前,它再次抛出异常“尝试从状态 READY 到状态 INITIALIZING 的无效转换”。
我究竟做错了什么?

最佳答案

每次只需为每笔交易创建新的生产者。

KafkaProducer producer = new KafkaProducer<>(props);
producer.initTransactions();
//transaction 1
producer.beginTransaction();
//send some messages
producer.commitTransaction();
producer.close();

KafkaProducer producer = new KafkaProducer<>(props);
producer.initTransactions();

//transaction 2
producer.beginTransaction(); //here it throws an exception "Invalid transition attempted from state IN_TRANSACTION to state IN_TRANSACTION".
//send some messages
producer.commitTransaction();

producer.close();

关于apache-kafka - 卡夫卡生产者抛出错误尝试从状态 IN_TRANSACTION 到状态 IN_TRANSACTION 的无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59864552/

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