![](/img/trans.png)
[英]Containerized kafka - cannot create transactions due to "Timeout expired after 60000 milliseconds while awaiting InitProducerId"
[英]Kafka transactional producer throws 'Timeout expired while initializing transactional state in 60000ms'
我已经配置了一个带有 transactionIdPrefix 的 Kafka ProducerFactory,以便使用@Transactional
启用事务同步(请参阅Spring producer-only transactions 文档)。
我在我的集成测试中运行了一个 EmbeddedKafka,以查看它的行为方式。
日志显示以下内容:
DEBUG 8384 --- [ad | producer-1] o.a.k.clients.producer.internals.Sender :
[Producer clientId=producer-1, transactionalId=tx-0-0]
Sending transactional request (type=FindCoordinatorRequest, coordinatorKey=tx-0-0, coordinatorType=TRANSACTION) to node 127.0.0.1:61445 (id: -1 rack: null)
DEBUG 8384 --- [ad | producer-1] o.a.k.c.p.internals.TransactionManager :
[Producer clientId=producer-1, transactionalId=tx-0-0]
Enqueuing transactional request (type=FindCoordinatorRequest, coordinatorKey=tx-0-0, coordinatorType=TRANSACTION)
Timeout expired while initializing transactional state in 60000ms.
当 DefaultKafkaProducerFactory 执行newProducer.initTransactions()
时抛出。
我的配置如下:
集成测试
@EmbeddedKafka(brokerProperties = { "transaction.state.log.replication.min.isr=1", "transaction.state.log.replication.factor=1" })
生产者配置
@Bean
public ProducerFactory<String, String> transactionalProducerFactory() {
Map<String, Object> configuration = new HashMap<>();
configuration.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.getBootstrapServers());
configuration.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configuration.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
String transactionIdPrefix = "tx-0-";
configuration.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
DefaultKafkaProducerFactory<String, String> factory = new DefaultKafkaProducerFactory<>(configuration);
factory.setTransactionIdPrefix(transactionIdPrefix);
return factory;
}
@Bean
public KafkaTemplate<String, String> transactionalKafka() {
return new KafkaTemplate<>(transactionalProducerFactory());
}
Spring-Kafka版本:2.2.7.RELEASE
我不知道如何前进,我认为我按照文档中的每一步进行操作,并且 Kafka 客户端和代理之间的通信在事务初始化期间应该没问题。 谁能帮我解决这个问题?
由于嵌入式 kafka 服务器日志,我可以解决问题。
属性transaction.state.log.min.isr
默认为 2,我不得不用transaction.state.log.min.isr = 1
覆盖它来修复服务器错误。 之后我的集成测试通过了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.