【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不同方向入手,别的软件也有类似的情况。

相关推荐
hh.h.7 小时前
Flutter与鸿蒙实现分布式设备搜索(含类型识别与在线状态标注)
分布式·flutter·harmonyos
晓源よ7 小时前
Vxlan集中式分布式网关详解与实验
分布式
编织幻境的妖7 小时前
Hadoop核心组件及其作用概述
大数据·hadoop·分布式
7 小时前
TIDB——TIDB Server
数据库·分布式·tidb
驾驭人生8 小时前
RabbitMQ 封装,基于原生 RabbitMQ.Client 实现
分布式·rabbitmq
回家路上绕了弯1 天前
分布式锁原理深度解析:从理论到实践
分布式·后端
heartbeat..1 天前
深入理解 Redisson:分布式锁原理、特性与生产级应用(Java 版)
java·分布式·线程·redisson·
Github掘金计划1 天前
开发者狂喜!GitHub 官方开源:支持 Copilot/Cursor,规范即代码,27k Star 封神!
java·python·kafka·github·copilot