我的 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/