spring boot 由2.6升级2.7 kafka报错问题汇总

本文解决Kafka中出现的事务执行错误、集群授权失败及idempotent producer配置问题,提供具体的Spring Kafka配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Cannot execute transactional method because we are in an error state Caused by: org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.

原因

sercurity.protocol 不全局化

解决方案
spring:
  kafka:
    bootstrap-servers: 
    properties:
      security.protocol: SASL_PLAINTEXT
      sasl.mechanism: SCRAM-SHA-256
      sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="" password="";

改动为 ->

spring:
  kafka:
    bootstrap-servers: 
    producer:
      acks: 1
      security:
        protocol: SASL_PLAINTEXT
    properties:
      sasl.mechanism: SCRAM-SHA-256
      sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="" password="";

2. No transaction is in process; possible solutions: run the template operation within the scope of a template.executeInTransaction() operation, start a transaction with @Transactional before invoking the template method, run in a transaction started by a listener container when consuming a record

解决方案
在方法上加@Transactional注解 
配置生产者 transaction-id-prefix:

3. Must set acks to all in order to use the idempotent producer. Otherwise we cannot guarantee idempotence.

解决方案
应答级别:多少个分区副本备份完成时向生产者发送ack确认(可选0、1、all/-1)
spring.kafka.producer.acks=-1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值