【Kafka】Kafka客户端认证失败:Cluster authorization failed.

背景

  1. kafka客户端是公司内部基于spring-kafka封装的
  2. spring-boot版本:3.x
  3. spring-kafka版本:2.1.11.RELEASE
  4. 集群认证方式:SASL_PLAINTEXT/SCRAM-SHA-512
  5. 经过多年的经验,以及实际验证,配置是没问题的,但是业务方反馈用相同的问题,还是报错!

错误日志

复制代码
2023-12-21 18:00:44.051 [kafka-producer-network-thread | producer-1] INFO  o.a.k.c.p.i.TransactionManager - [Producer clientId=producer-1] Transiting to fatal error state due to org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2023-12-21 18:00:44.066 [http-nio-8082-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.apache.kafka.common.KafkaException: Cannot execute transactional method because we are in an error state] with root cause
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2023-12-21 18:00:44.156 [kafka-producer-network-thread | producer-1] ERROR o.a.k.c.producer.internals.Sender - [Producer clientId=producer-1] Aborting producer batches due to fatal error
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2023-12-21 18:00:44.159 [kafka-producer-network-thread | producer-1] ERROR o.s.k.s.LoggingProducerListener - Exception thrown when sending a message with key='null' and payload='测试消息' to topic test-topic:
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.

原因

封装的kafka客户端版本过低,高版本的配置项:security.protocol 的key已经换了,需要把配置项改为低版本的。

IDEA有提示,如果发现配置项不能解析或不识别,说明该配置项不正确。

具体从哪个版本开始改的,看了一遍github上的版本迭代记录,并没有提及,只能是遇到的时候多注意,有问题进行切换即可。

  • 低版本使用:spring.kafka.properties.security.protocol=SASL_PLAINTEXT
  • 高版本使用:spring.kafka.security.protocol=SASL_PLAINTEXT

问题不好排查,尤其是公司自己封装的客户端,配置项和springboot-kafka不太一样,IDEA也没有提示,可以作为一个经验吧,当配置都确认无误时,还是报错或配置不生效,尝试从因版本变更导致配置项key不同方向入手,别的软件也有类似的情况。

相关推荐
茶杯梦轩1 天前
从零起步学习RabbitMQ || 第三章:RabbitMQ的生产者、Broker、消费者如何保证消息不丢失(可靠性)详解
分布式·后端·面试
IvanCodes1 天前
一、消息队列理论基础与Kafka架构价值解析
大数据·后端·kafka
回家路上绕了弯3 天前
深入解析Agent Subagent架构:原理、协同逻辑与实战落地指南
分布式·后端
初次攀爬者3 天前
Kafka的Rebalance基础介绍
后端·kafka
初次攀爬者4 天前
Kafka + KRaft模式架构基础介绍
后端·kafka
初次攀爬者4 天前
Kafka + ZooKeeper架构基础介绍
后端·zookeeper·kafka
初次攀爬者4 天前
Kafka 基础介绍
spring boot·kafka·消息队列
DemonAvenger8 天前
Kafka性能调优:从参数配置到硬件选择的全方位指南
性能优化·kafka·消息队列
初次攀爬者8 天前
ZooKeeper 实现分布式锁的两种方式
分布式·后端·zookeeper