当使用较新版本SpringBoot时,对应的 kafka-client 版本也比较新,如果使用了 2.x 以上的 kafka-client ,并且配置了 kafka ssl 连接方式时,可能会报如下异常:

javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack?

.....

org.apache.kafka.common.errors.SslAuthenticationException: SSL handshake failed
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem ..... Caused by: java.security.cert.CertificateException: No subject alternative names present ..... 2019-10-09 10:12:55.683 DEBUG 23524 --- [ main] o.s.kafka.core.KafkaTemplate : Failed to send: ProducerRecord .....

该原因是因为新版本 kafka-client 会校验证书的主机名,配置忽略主机名校验即可。

配置方法主要代码如下:

 spring:
kafka:
properties:
ssl:
endpoint:
identification:
algorithm: ''

另附SpringBoot 使用 ssl 证书连接 kafka 完整配置如下:

 ########## kafka ##########
spring:
kafka:
producer:
batch-size: 16384
retries: 1
buffer-memory: 33554432
bootstrap-servers: 192.168.1.100:9092
value-serializer: org.apache.kafka.common.serialization.StringSerializer
key-serializer: org.apache.kafka.common.serialization.StringSerializer
consumer:
group-id: test-group-001
auto-offset-reset: earliest
auto-commit-interval: 100
bootstrap-servers: 192.168.1.100:9092
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
enable-auto-commit: true
ssl:
protocol: SSL
trust-store-type: JKS
trust-store-location: file:D:/source-files/kafka/kafkatest.client.truststore.test.jks
trust-store-password: 123456
key-store-type: JKS
key-store-location: file:D:/source-files/kafka/kafkatest.client.keystore.test.jks
key-store-password: 123456
key-password: 123456
properties:
ssl:
endpoint:
identification:
algorithm: ''
security:
protocol: SSL

问题解决。

SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决的更多相关文章

  1. java.security.cert.CertificateException: No subject alternative names present

    背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码; 后来,需求变更要求兼容https协议的webserv ...

  2. JDK安全证书的一个错误消息 No subject alternative names present的解决办法

    我使用Java消费某网站一个Restful API时,遇到这个错误: 21:31:16.383 [main] DEBUG org.springframework.web.client.RestTemp ...

  3. 用HttpClient发送HTTPS请求报SSLException: Certificate for <域名> doesn't match any of the subject alternative names问题的解决

    最近用server酱-PushBear做消息自动推送,用apache HttpClient做https的get请求,但是代码上到服务器端就报javax.net.ssl.SSLException: Ce ...

  4. java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found

    https与http不同的是,https加密,需要验证证书,而http不需要. 在连接的代码中加上: static { disableSslVerification(); } private stat ...

  5. 【java细节】Java代码忽略https证书:No subject alternative names present

    https://blog.csdn.net/audioo1/article/details/51746333

  6. 关于springboot 连接mysql 数据库报错问题

    springboot连接MySQL运行报错: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more ...

  7. 使用HttpClient携带证书报错_Certificate for <IP> doesn't match any of the subject alternative names:[域名]

    使用HttpClient携带pfx证书通过Https协议发送SOUP报文调用WebService接口时报如下错误: Exception in thread "main" javax ...

  8. Aandroid 解决apk打包过程中出现的“Certificate for <jcenter.bintray.com> doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题

    有时候,apk打包过程中会出现“Certificate for <jcenter.bintray.com> doesn't match any of the subject alterna ...

  9. 【PostgreSQL】PostgreSQL添加新服务器连接时,报错“Server doesn't listen ”,已解决。

    PostgreSQL添加新的服务器连接时,报错:

随机推荐

  1. MySQL如何选择合适的索引

    先来看一个栗子 EXPLAIN select * from employees where name > 'a'; 如果用name索引查找数据需要遍历name字段联合索引树,然后根据遍历出来的主 ...

  2. addTarget原理

    addTarget原理: 当一个控件addTarget时,先到runLoop注册,然后runLoop才会监听该事件,事件处理按照响应者链条   以下以button为例图解:

  3. Educational Codeforces Round 43 E&976E. Well played! 贪心

    传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...

  4. 微信小程序一步一步获取UnionID,实现自动登录

    思路: 1.小程序端获取用户ID,发送至后台 2.后台查询用户ID,如果找到了该用户,返回Token,没找到该用户,保存到数据库,并返回Token 小程序端如何获取用户ID: 小程序端 wx.getU ...

  5. 适合C++のOIer平日写题的开场模板

    上面的#define还是较充足的,快读模板也有,freopen也提前打好了,比较适合OIer(C++)平时刷题和考试的开场. (纯原版仅供SJZEZのORZ队&AFO队使用) (您老把开头的注 ...

  6. Python高效编程技巧实战 实战编程+面试典型问题 中高阶程序员过渡

    下载链接:https://www.yinxiangit.com/603.html 目录:   如果你想用python从事多个领域的开发工作,且有一些python基础, 想进一步提高python应用能力 ...

  7. spring boot项目后台运行

    spring boot项目后台运行 Spring Boot应用的几种运行方式: (1)运行Spring Boot的应用主类 (2)使用Maven的Spring Boot插件mvn spring-boo ...

  8. linux中启动Zookeeper

    1.先把zookeeper的安装包解压在/usr/local,如下: 2.进入zookeeper目录,创建一个data目录 3.进入同级conf目录下,里面有zoo_sample.cfg,修改该文件名 ...

  9. xml文档的解析并通过工具类实现java实体类的映射:XML工具-XmlUtil

    若有疑问,可以联系我本人微信:Y1141100952 声明:本文章为原稿,转载必须说明 本文章地址,否则一旦发现,必追究法律责任 1:本文章显示通过 XML工具-XmlUtil工具实现解析soap报文 ...

  10. PLC与上位机的socket通讯——上位机C#程序(二)

    C#的网口通信 一.命令行 客户端程序:using System;using System.Collections.Generic;using System.Linq;using System.Tex ...