<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>39点博客</title><link>https://39dian.com/</link><description>优秀IT博客分享平台</description><item><title>配置Nginx正向代理让老项目适配Https的TLS高版本</title><link>https://39dian.com/?id=56</link><description>&lt;p&gt;最近生产有个项目访问第三方接口时突然报异常了，查下来是因为对方升级了Https的TLS版本到1.2，不再支持1.0和1.1。&lt;/p&gt;&lt;p&gt;因为是老项目用的还是jdk1.6，默认是不支持的TLS1.2的。代码久远很久没有维护想再升级jdk比较困难，有可能还会导致其他的未知问题。所以想到能否在服务器上配置一个代理来做请求转发，大致思路如下：&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2024/07/202407101720582160277619.png&quot; alt=&quot;image.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;说干就干，按步骤实现&lt;/p&gt;&lt;p&gt;&lt;strong&gt;第一步：配置服务器上的hosts&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;修改路径：/etc/hosts，127.0.0.1 localApi，这里的ip是nginx的内网地址，这里是直接在项目服务器上安装了个nginx&lt;/p&gt;&lt;p&gt;&lt;strong&gt;第二步：配置nginx正向代理&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-bash&quot;&gt;server&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;代理端口
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listen&amp;nbsp;6789;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;server_name&amp;nbsp;localApi;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location&amp;nbsp;/&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;正向代理配置，根据请求地址自动解析出目标网站地址并进行代理
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;proxy_pass&amp;nbsp;https://api.xxxxxxxxxxx.com;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;access_log&amp;nbsp;/var/log/nginx/proxyAccess.log&amp;nbsp;main;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error_log&amp;nbsp;/var/log/nginx/proxyError.log;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;&lt;br/&gt;&lt;/strong&gt;&lt;strong style=&quot;white-space: normal;&quot;&gt;第三步：使用curl命令测试&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;敲击命令：curl &lt;a href=&quot;http://localApi:6789&quot; _src=&quot;http://localApi:6789&quot;&gt;http://localApi:6789&lt;/a&gt; &lt;/p&gt;&lt;p&gt;收到对方接口正常返回，验证成功。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;第四步：修改项目中的接口地址&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;将原接口地址：&lt;a href=&quot;https://api.xxxxxxxxxxx.com&quot; _src=&quot;https://api.xxxxxxxxxxx.com&quot;&gt;https://api.xxxxxxxxxxx.com&lt;/a&gt;&amp;nbsp;修改为：&lt;a href=&quot;http://localapi:6789/&quot; _src=&quot;http://localApi:6789&quot; style=&quot;white-space: normal;&quot;&gt;http://localApi:6789&lt;/a&gt;&lt;/p&gt;&lt;p&gt;验证：发起业务请求成功收到响应！&lt;/p&gt;&lt;p&gt;至此改造完成。&lt;/p&gt;</description><pubDate>Wed, 10 Jul 2024 11:01:56 +0800</pubDate></item><item><title>解决Jmeter压测勾选KeepAlive后请求失败率50%的问题</title><link>https://39dian.com/?id=55</link><description>&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;最近在做接口压力测试的时候发现每次请求失败率都在50%，Jmeter版本5.6，如下图：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2023/08/202308031691046896609763.png&quot; alt=&quot;image.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2023/08/202308031691044189883804.png&quot; alt=&quot;image.png&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;刚开始以为是压测服务器资源不够导致应用拒绝链接，然后观察了下执行任务的时候CPU和内存并没有耗尽，于是从应用本身找问题。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;该WEB应用是基于Netty构建的，Netty在最外层作为通信网关处理权限验证，权限验证通过后解析URL参数，再根据参数反射调用对应的业务处理类方法。Netty的角色类似Spring MVC中Controller层。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;NettyServer的onApplicationEvent方法是很通用的实现，如下图：&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2023/08/202308031691045116268115.png&quot; alt=&quot;image.png&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;尝试加入以下代码支持keep-alive，仍然请求失败，并未起到效果。&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;宋体&amp;#39;;font-size:12.0pt;&quot;&gt;childOption(NioChannelOption.)
.childOption(NioChannelOption.(StandardSocketOptions.))
channelPipeline.addLast(&amp;nbsp;&amp;quot;idleCheckHandler&amp;quot;,&amp;nbsp;new&amp;nbsp;IdleStateHandler(5,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5,&amp;nbsp;5,&amp;nbsp;TimeUnit.SECONDS));&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;继续查看HttpServerHandler处理类的channelRead&lt;/span&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;(ChannelHandlerContext ctx, FullHttpRequest request)方法，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;在代码的末尾处发现如下代码，正常情况下Http请求响应后立即关闭连接逻辑上是没有问题的。但是一般实际应用过程中，web容器都会设置一个keep-alive时长保持连接，超时后服务器再主动关闭该TCP连接，这样会减少客户端和服务器之间的握手次数，短时间内同一客户端向服务器发送多个HTTP请求可以使用同一个TCP连接通道以保证高效通信。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2023/08/202308031691045493543308.png&quot; alt=&quot;image.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;找到问题所在也就好解决了，方法末尾不要立即关闭连接，改用延迟关闭连接。延迟时间参考springBoot中对tomcat的设置，如下：&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;server.tomcat.keep-alive-timeout=60000 ;保持每个会话活动的不活动毫秒数&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;server.tomcat.max-keep-alive-requests=100 ;保持活动会话数，默认值为100&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;</description><pubDate>Thu, 03 Aug 2023 14:18:49 +0800</pubDate></item><item><title>软考从中级到高级一次通关心得--高级篇</title><link>https://39dian.com/?id=52</link><description>&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;今天是&lt;/span&gt;2021&lt;span style=&quot;font-family:宋体&quot;&gt;最后一个工作日，闲下来把之前未写完的备考心得给补上。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;上半年软考中级考完之后就一直琢磨着再考个高级。高级跟中级“软件设计师”类似的有两个科目：系统分析师和系统架构师。系统分析师是上半年考，下半年考系统架构师，每年都只考一次，所以能选的只有&lt;/span&gt;11&lt;span style=&quot;font-family:宋体&quot;&gt;月份开考的系统架构师。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;首先是定制备考策略，分析自身情况，有以下几个阻力：工作日要上班、周末要带娃、没有整块时间、不制定明确目标就会懒散、不想花钱报课。结合以上情况之后决定下来还是跟考中级一样，刷题！高级一共要考&lt;/span&gt;3&lt;span style=&quot;font-family:宋体&quot;&gt;门，上午考选择题，下午考案例分析和论文。因为是&lt;/span&gt;11&lt;span style=&quot;font-family:宋体&quot;&gt;月份考试所以不需要太早备考，我是从&lt;/span&gt;8&lt;span style=&quot;font-family:宋体&quot;&gt;月份开始备考的。下面分别针对这三门考试做简单的分析吧。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;首先是选择题，选择题备考是相对简单的，下载一个手机&lt;/span&gt;app&lt;span style=&quot;font-family:宋体&quot;&gt;刷题，每天随机练习&lt;/span&gt;10&lt;span style=&quot;font-family:宋体&quot;&gt;道真题，上下班在地铁上看。这里重要的一点是每天都要坚持，如果某一天有事情耽搁了第二天就要补上，做&lt;/span&gt;20&lt;span style=&quot;font-family:宋体&quot;&gt;题。高级的选择题一小部分知识点和中级是重合的，高级考的会更细。比如&lt;/span&gt;mccabe&lt;span style=&quot;font-family:宋体&quot;&gt;环路复杂度、测试案例的分支覆盖、二叉树和数据结构、数据库知识。还有一些是高级中特有的知识点，如：架构风格、需求管理、嵌入式、架构设计方法等。最后还有&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;道英语题。总的来说只要刷题足够多，选择题通过还是不难的。上午考试有&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;个半小时，时间充裕，可以反复检查。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;然后是下午的案例分析题，一共&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;道题，第一题必做，后面&lt;/span&gt;4&lt;span style=&quot;font-family:宋体&quot;&gt;选&lt;/span&gt;2.&lt;span style=&quot;font-family:宋体&quot;&gt;，后面&lt;/span&gt;4&lt;span style=&quot;font-family:宋体&quot;&gt;题中必有一道嵌入式题，无嵌入式专业经验的可以直接放弃&lt;/span&gt;。也就是说一共要做3&lt;span style=&quot;font-family:宋体&quot;&gt;题，每题&lt;/span&gt;25&lt;span style=&quot;font-family:宋体&quot;&gt;分。第一道必做题最近几年主要考的都是系统的&lt;/span&gt;6&lt;span style=&quot;font-family:宋体&quot;&gt;大质量属性：性能、安全性、可用性、可修改性、易用性、可测试性。和系统架构设计风格的比较和分析。后面&lt;/span&gt;4&lt;span style=&quot;font-family:宋体&quot;&gt;选&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;题中有数据流图、&lt;/span&gt;web&lt;span style=&quot;font-family:宋体&quot;&gt;系统架构设计、数据库和分布式缓存，结合日常工作情况选适合自己的题目。对于有工作经验的同学来说案例分析题并不是很难，但是考试时间有点短，只有一个半小时，考试的时候要把握好时间。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;最后是论文，也是难点。大部分考试不通过的都是挂在论文上。首先是考试安排上，上午选择题考完要动脑子废掉了一部分脑细胞，然后下午&lt;/span&gt;1:30-3:00&lt;span style=&quot;font-family:宋体&quot;&gt;又考案例分析，中途只休息&lt;/span&gt;20&lt;span style=&quot;font-family:宋体&quot;&gt;分钟，&lt;/span&gt;3:20&lt;span style=&quot;font-family:宋体&quot;&gt;立马考论文。在考案例分析的时候已经写了很多文字了，论文又要求写作不低于&lt;/span&gt;2500&lt;span style=&quot;font-family:宋体&quot;&gt;字，考试时间只有&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;个小时。就算一直埋头写，&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;个小时写&lt;/span&gt;2500&lt;span style=&quot;font-family:宋体&quot;&gt;字也是很紧张的。所以论文一定要提前准备好。论文一共有&lt;/span&gt;4&lt;span style=&quot;font-family:宋体&quot;&gt;道题目，选一个写就可以了。最近几年考的比较多的有架构风格、软件设计方法和应用、系统架构评估、微服务架构设计、软件开发过程等。提前准备&lt;/span&gt;3-5&lt;span style=&quot;font-family:宋体&quot;&gt;篇论文，摘要、核心论点要紧扣论题。考试前需要把准备好的论文手写几遍，注意时间，&lt;/span&gt;2500&lt;span style=&quot;font-family:宋体&quot;&gt;字在&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;小时内写完。因为我也是第一次考，准备的比较充分，最后以&lt;/span&gt;46&lt;span style=&quot;font-family:宋体&quot;&gt;分险过。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;最近几年也确实没什么进步，一直在原地踏步，收获的只有年龄和白头发。考证的主要目的也还是为了落户，高级证可以聘用高级职称，以人才引进的方式落户，但是有个前提条件，需要中级职称满&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;年，奈何中级证书我还是上半年才考的，只能怪自己意识太晚。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;明天就是除夕了，准备收拾收拾办公桌回家过年。明年来的时候再合计下还有哪些事情没有做的，凡事还是要趁早。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 30 Jan 2022 10:36:15 +0800</pubDate></item><item><title>软考从中级到高级一次通关心得--中级篇</title><link>https://39dian.com/?id=51</link><description>&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 算了下今年已经是工作的第十个年头了，在&lt;/span&gt;IT&lt;span style=&quot;font-family:宋体&quot;&gt;行业已是“老人”。年初在微信群里闲聊，得知一位朋友在考中级职称。因我刚开始来上海那几年没有办居住证导致持证年限不满&lt;/span&gt;7&lt;span style=&quot;font-family:宋体&quot;&gt;年未达到居转户的条件，所以虽然原先有这个意识但是一直未提上日程。又想了想最近几年除了复制粘贴代码外自身能力也没有得到提升，遂在他的“鼓动”下决定备考中级，为后面的落户做准备。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 看了下中级科目，软件设计师较符合程序猿职业报考，于是报考了&lt;/span&gt;21&lt;span style=&quot;font-family:宋体&quot;&gt;年&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;月份的考试。考试分上午选择题和下午简答题，各&lt;/span&gt;75&lt;span style=&quot;font-family:宋体&quot;&gt;分，上午题是&lt;/span&gt;75&lt;span style=&quot;font-family:宋体&quot;&gt;个选择题，下午是&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;道简答题每题15分，需要&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;门同时满足&lt;/span&gt;45&lt;span style=&quot;font-family:宋体&quot;&gt;分以上算通过。了解清楚考试规则后，接下来就是制定备考方案和计划了。首先分析自身的优缺点再去制定计划，我是属于很懒散的人，看书看视频复习是不适合我，我也没有这个毅力和整块时间去看书看视频。所以我的策略是刷题并严格执行备考计划。提前&lt;/span&gt;3&lt;span style=&quot;font-family:宋体&quot;&gt;个月准备，第一个月每天看&lt;/span&gt;10&lt;span style=&quot;font-family:宋体&quot;&gt;道选择题，手机下网上载刷题&lt;/span&gt;app&lt;span style=&quot;font-family:宋体&quot;&gt;，上下班地铁上看一下，这对于刚开始备考的同学是很重要的，因为工作久了就很难进入系统性的复习和备考习惯，这第一个月算是预热期，每天&lt;/span&gt;10&lt;span style=&quot;font-family:宋体&quot;&gt;道选择题也就&lt;/span&gt;20-30&lt;span style=&quot;font-family:宋体&quot;&gt;分钟的事情是很容易坚持下来的。第二个月除了每天&lt;/span&gt;10&lt;span style=&quot;font-family:宋体&quot;&gt;道选择题之外再加上每&lt;/span&gt;2&lt;span style=&quot;font-family:宋体&quot;&gt;天做一道下午简答题，复习时间也由原先的每天&lt;/span&gt;20-30&lt;span style=&quot;font-family:宋体&quot;&gt;分钟上升到&lt;/span&gt;30-50&lt;span style=&quot;font-family:宋体&quot;&gt;分钟。最后一个月临近考试了需要将最近&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;年的真题找出来做一遍。最终算了一下总共大概做了&lt;/span&gt;1000&lt;span style=&quot;font-family:宋体&quot;&gt;道选择和&lt;/span&gt;80&lt;span style=&quot;font-family:宋体&quot;&gt;道简答题，换算下来是&lt;/span&gt;15&lt;span style=&quot;font-family:宋体&quot;&gt;套上午卷和&lt;/span&gt;15&lt;span style=&quot;font-family:宋体&quot;&gt;套下午卷。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 对于像我这样工作久了很久没有碰书本的人来说，重新把知识拾起来再系统性的复习一遍并不像网上说的那样简单，考试的内容很多也并非工作上常用的。上午的选择题涉及的知识面较广，有计算机组成原理、排序算法、海明码、&lt;/span&gt;mccabe&lt;span style=&quot;font-family:宋体&quot;&gt;、二叉树哈夫曼树、各种测试方法的覆盖范围、网络基础知识等等。对了，上午题还有&lt;/span&gt;5&lt;span style=&quot;font-family:宋体&quot;&gt;道英语选择题（阅读理解）。要结合自身情况做一些取舍，比如我觉得英语题一时半会也没法显著提升，复习阶段就放弃了英语题目的备考。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 下午简答题前面&lt;/span&gt;4&lt;span style=&quot;font-family:宋体&quot;&gt;道题是必答题，后面一道&lt;/span&gt;JAVA&lt;span style=&quot;font-family:宋体&quot;&gt;题目和&lt;/span&gt;C++&lt;span style=&quot;font-family:宋体&quot;&gt;题二选一，每题&lt;/span&gt;15&lt;span style=&quot;font-family:宋体&quot;&gt;分。第一题是考的是数据流图，要求补全图上的各个实体、加工、数据存储以及确实的数据流的起点和终点，这一题相对来说不是太难。第二题是数据库题，考关系模式、主外键、三范式以及找缺失的联系和联系类型，对于工作经验丰富的&lt;/span&gt;“&lt;span style=&quot;font-family:宋体&quot;&gt;老鸟&lt;/span&gt;”&lt;span style=&quot;font-family:宋体&quot;&gt;来说这一题平时工作上都会用到，稍加复即可。第三题一般考用例图，需要填写参与者、各用例名称、类名等。第四题是最难的，考&lt;/span&gt;C&lt;span style=&quot;font-family:宋体&quot;&gt;语言算法，这一题是难点，每年考的内容也无迹可寻，基于这一点我在备考的时候直接放弃了，考试的时候临场发挥看运气了，我估摸着大概也就拿了&lt;/span&gt;3&lt;span style=&quot;font-family:宋体&quot;&gt;分左右吧&lt;/span&gt;~&lt;span style=&quot;font-family:宋体&quot;&gt;。最后一题是&lt;/span&gt;C++&lt;span style=&quot;font-family:宋体&quot;&gt;和&lt;/span&gt;Java&lt;span style=&quot;font-family:宋体&quot;&gt;题二选一，这对于从事这两种语言开发的小伙伴来说是稳稳的送分题。相比于上午选择题，下午的简答题是难点，其中第四题&lt;/span&gt;C&lt;span style=&quot;font-family:宋体&quot;&gt;语言算法题是难点中的难点，如果这一题没有把握，那另外四道题目势必要拿高分才能过关。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 说了这么多，实际上最终我也才考了&lt;/span&gt;52/45&lt;span style=&quot;font-family:宋体&quot;&gt;分，算是极限通过，但对于好多年未碰过书本并专注于&lt;/span&gt;CTRL+C&lt;span style=&quot;font-family:宋体&quot;&gt;和&lt;/span&gt;CTRL+V&lt;span style=&quot;font-family:宋体&quot;&gt;多年的程序老鸟来说通过即是一种安慰。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 考过了中级，对自身就稍微有了点信心，就琢磨着趁热打铁，再一鼓作气争取拿下高级。后面有时间再单独写一篇高级的备考心得，这篇就到先到这里了~&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&amp;nbsp; &amp;nbsp; 最后附上几张中级备考的草稿证明复习过，以后闲下来的时候也可以回过头来看一看~&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2022/01/202201041641274994692219.png&quot; style=&quot;&quot; title=&quot;1.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2022/01/202201041641274994374811.png&quot; style=&quot;&quot; title=&quot;2.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2022/01/202201041641274995741609.png&quot; style=&quot;&quot; title=&quot;4.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2022/01/202201041641274995189775.png&quot; style=&quot;&quot; title=&quot;5.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://39dian.com/zb_users/upload/2022/01/202201041641274995422212.png&quot; style=&quot;&quot; title=&quot;6.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:宋体&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 30 Dec 2021 13:25:22 +0800</pubDate></item><item><title>CentOS安装docker并配置镜像加速器</title><link>https://39dian.com/?id=54</link><description>&lt;h2 class=&quot;text-muted&quot; data-spm-anchor-id=&quot;5176.8351553.0.i3.513219917cT3Tf&quot; style=&quot;box-sizing: border-box; font-weight: var(--font-weight-medium,500); margin-top: 20px; margin-bottom: 13px; font-size: var(--font-size-title,16px); line-height: 30px; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255); color: rgb(102, 102, 102) !important;&quot;&gt;1. 安装／升级Docker客户端&lt;/h2&gt;&lt;pre class=&quot;prism-highlight prism-language-bash&quot;&gt;#&amp;nbsp;step&amp;nbsp;1:&amp;nbsp;安装必要的一些系统工具
sudo&amp;nbsp;yum&amp;nbsp;install&amp;nbsp;-y&amp;nbsp;yum-utils&amp;nbsp;device-mapper-persistent-data&amp;nbsp;lvm2
#&amp;nbsp;Step&amp;nbsp;2:&amp;nbsp;添加软件源信息
sudo&amp;nbsp;yum-config-manager&amp;nbsp;--add-repo&amp;nbsp;http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#&amp;nbsp;Step&amp;nbsp;3:&amp;nbsp;更新并安装&amp;nbsp;Docker-CE
sudo&amp;nbsp;yum&amp;nbsp;makecache&amp;nbsp;fast
sudo&amp;nbsp;yum&amp;nbsp;-y&amp;nbsp;install&amp;nbsp;docker-ce
#&amp;nbsp;Step&amp;nbsp;4:&amp;nbsp;开启Docker服务
sudo&amp;nbsp;systemctl&amp;nbsp;start&amp;nbsp;docker
#&amp;nbsp;Step&amp;nbsp;5:&amp;nbsp;设置开机启动
sudo&amp;nbsp;systemctl&amp;nbsp;enable&amp;nbsp;docker&lt;/pre&gt;&lt;h2 class=&quot;text-muted&quot; data-spm-anchor-id=&quot;5176.8351553.0.i4.513219917cT3Tf&quot; style=&quot;box-sizing: border-box; font-weight: var(--font-weight-medium,500); margin-top: 20px; margin-bottom: 13px; font-size: var(--font-size-title,16px); line-height: 30px; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255); color: rgb(102, 102, 102) !important;&quot;&gt;2. 配置镜像加速器&lt;/h2&gt;&lt;p&gt;&lt;span style=&quot;color: #666666; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 12px; background-color: #FFFFFF;&quot;&gt;通过修改daemon配置文件&lt;/span&gt;&lt;span class=&quot;textRed&quot; data-spm-anchor-id=&quot;5176.8351553.0.i6.513219917cT3Tf&quot; style=&quot;box-sizing: border-box; color: #C7254E; padding: 0px 4px; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 12px; background-color: #FFFFFF;&quot;&gt;/etc/docker/daemon.json&lt;/span&gt;&lt;span style=&quot;color: #666666; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 12px; background-color: #FFFFFF;&quot;&gt;来使用加速器&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-bash&quot;&gt;sudo&amp;nbsp;mkdir&amp;nbsp;-p&amp;nbsp;/etc/docker
sudo&amp;nbsp;tee&amp;nbsp;/etc/docker/daemon.json&amp;nbsp;&amp;lt;&amp;lt;-&amp;#39;EOF&amp;#39;
{
&amp;nbsp;&amp;nbsp;&amp;quot;registry-mirrors&amp;quot;:&amp;nbsp;[&amp;quot;https://y6tra9hx.mirror.aliyuncs.com&amp;quot;]
}
EOF
sudo&amp;nbsp;systemctl&amp;nbsp;daemon-reload
sudo&amp;nbsp;systemctl&amp;nbsp;restart&amp;nbsp;docker&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #666666; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 12px; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 04 Jul 2021 09:20:13 +0800</pubDate></item><item><title>RabbitMQ消息幂等性问题</title><link>https://39dian.com/?id=53</link><description>&lt;h3 id=&quot;h1&quot; style=&quot;margin: 1.6em 0px; padding-top: 0px; padding-bottom: 0px; color: inherit; font-size: 1.3em; line-height: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); border-bottom: 2px solid rgb(239, 112, 96);&quot;&gt;&lt;span style=&quot;margin: 0px 3px 0px 0px; padding: 3px 10px 1px; font-size: inherit; line-height: inherit; display: inline-block; font-weight: normal; background: #EF7060; color: #FFFFFF; border-top-right-radius: 3px; border-top-left-radius: 3px;&quot;&gt;1. 什么是幂等性？&lt;/span&gt;&lt;/h3&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;在编程中一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;HTTP方法的幂等性是指一次和多次请求某一个资源应该具有同样的副作用。幂等性属于语义范畴，正如编译器只能帮助检查语法错误一样，HTTP规范也没有办法通过消息格式等语法手段来定义它。&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;简之：一个请求，不管重复来多少次，结果是不会改变的。&lt;/strong&gt;&lt;/p&gt;&lt;h4 id=&quot;h11&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; line-height: inherit; font-size: 1.2em; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;1.1 消息队列的幂等性&lt;/span&gt;&lt;/h4&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;如同HTTP方法的幂等性，消息队列同样会出现幂等性问题。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;消费者在消费 MQ 中的消息时，MQ 已把消息发送给消费者，消费者在给 MQ 返回 ack 时网络中断，故 MQ 未收到确认信息，该条消息会重新发给其他的消费者，或者在网络重连后再次发送给该消费者，但实际上该消费者已成功消费了该条消息，造成消费者消费了重复的消息；注意，RabbitMQ 这种消息重试(补偿)机制是默认的。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;所以，MQ 消费者的幂等性问题，主要在于 MQ 的重试机制，因为网络原因或客户端延迟消费导致重复消费。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;那么，如何合适选择重试机制？我们来看两种情况。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;情况1：&lt;/strong&gt;&amp;nbsp;消费者获取到消息后，调用第三方接口，但接口暂时无法访问，是否需要重试?&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;需要重试&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;情况2：&lt;/strong&gt;&amp;nbsp;消费者获取到消息后，抛出数据转换异常，是否需要重试?&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;不需要重试&lt;/p&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;总结：对于情况2，如果消费者代码抛出异常是需要发布新版本才能解决的问题，那么不需要重试，重试也无济于事。应该采用日志记录+定时任务 job 健康检查+人工进行补偿&lt;/p&gt;&lt;/blockquote&gt;&lt;h4 id=&quot;h12&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; line-height: inherit; font-size: 1.2em; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;1.2 模拟重试机制&lt;/span&gt;&lt;/h4&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;我们采用一种短信消费者客户端异常的情况来模拟 RabbitMQ 的重试机制。&lt;/p&gt;&lt;pre highlighted=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;@RabbitListener(queues&amp;nbsp;=&amp;nbsp;&amp;quot;fanout_sms_queue&amp;quot;)public&amp;nbsp;void&amp;nbsp;process(String&amp;nbsp;msg)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;短信消费者获取生产者消息msg:&amp;quot;&amp;nbsp;+&amp;nbsp;msg);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;1/0;
}&lt;/pre&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;如上代码，很显然会报错，一担报错生产者的消息时不会被消费的？&lt;/p&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;@RabbitListener 底层使用 AOP 进行异常通知拦截，如果程序没有抛出异常信息，那么就会自动提交事务；如果 AOP 异常通知拦截有捕获到异常信息的话，就会自动实现重试(补偿)机制，同时，这个补偿机制的消息会缓存到 RabbitMQ 服务器端进行存放，一直重试到不抛出异常为止。&lt;/p&gt;&lt;/blockquote&gt;&lt;h5 id=&quot;h121&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; font-size: 1em; line-height: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;1.2.1 生产者代码&lt;/span&gt;&lt;/h5&gt;&lt;pre highlighted=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;@Componentpublic&amp;nbsp;class&amp;nbsp;FanoutProducer&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Autowired&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;AmqpTemplate&amp;nbsp;amqpTemplate;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;发送消息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@param&amp;nbsp;queueName&amp;nbsp;队列名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;send(String&amp;nbsp;queueName)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;&amp;quot;my_fanout_msg:&amp;quot;&amp;nbsp;+&amp;nbsp;System.currentTimeMillis();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Message&amp;nbsp;message&amp;nbsp;=&amp;nbsp;MessageBuilder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.withBody(msg.getBytes())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setContentType(MessageProperties.CONTENT_TYPE_JSON)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setContentEncoding(&amp;quot;utf-8&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setMessageId(UUID.randomUUID()&amp;nbsp;+&amp;nbsp;&amp;quot;&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.build();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(msg&amp;nbsp;+&amp;nbsp;&amp;quot;:&amp;quot;&amp;nbsp;+&amp;nbsp;msg);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;amqpTemplate.convertAndSend(queueName,&amp;nbsp;message);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;h5 id=&quot;h122&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; font-size: 1em; line-height: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;1.2.2 消费者代码&lt;/span&gt;&lt;/h5&gt;&lt;pre highlighted=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;@Componentpublic&amp;nbsp;class&amp;nbsp;FanoutEamilConsumer&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@RabbitListener(queues&amp;nbsp;=&amp;nbsp;&amp;quot;fanout_eamil_queue&amp;quot;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;process(Message&amp;nbsp;message)&amp;nbsp;throws&amp;nbsp;Exception&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;revMessage&amp;nbsp;=&amp;nbsp;Thread.currentThread().getName()&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;,邮件消费者获取生产者消息msg:&amp;quot;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;new&amp;nbsp;String(message.getBody(),&amp;nbsp;&amp;quot;UTF-8&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;,messageId:&amp;quot;&amp;nbsp;+&amp;nbsp;message.getMessageProperties().getMessageId();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(revMessage);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;h5 id=&quot;h123applicationyml&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; font-size: 1em; line-height: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;1.2.3 消费者 application.yml 配置&lt;/span&gt;&lt;/h5&gt;&lt;pre highlighted=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;spring:
&amp;nbsp;&amp;nbsp;rabbitmq:
&amp;nbsp;&amp;nbsp;####连接地址&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host:&amp;nbsp;127.0.0.1&amp;nbsp;&amp;nbsp;&amp;nbsp;####端口号&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port:&amp;nbsp;5672&amp;nbsp;&amp;nbsp;&amp;nbsp;####账号&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username:&amp;nbsp;guest
&amp;nbsp;&amp;nbsp;&amp;nbsp;####密码&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;guest
&amp;nbsp;&amp;nbsp;&amp;nbsp;###&amp;nbsp;地址&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual-host:&amp;nbsp;/admin_host
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listener:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;simple:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;retry:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;####开启消费者重试&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;enabled:&amp;nbsp;true&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;####最大重试次数&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-attempts:&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;####重试间隔次数&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;initial-interval:&amp;nbsp;3000server:
&amp;nbsp;&amp;nbsp;port:&amp;nbsp;8081&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;我们通过 RabbitMQ 配置，增加了 RabbitMQ 重试时间以及重试次数限制，在一定程度上解决了重复消费的问题，接下来看一道常问的面试题。&lt;/p&gt;&lt;/blockquote&gt;&lt;h3 id=&quot;h2&quot; style=&quot;margin: 1.6em 0px; padding-top: 0px; padding-bottom: 0px; color: inherit; font-size: 1.3em; line-height: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); border-bottom: 2px solid rgb(239, 112, 96);&quot;&gt;&lt;span style=&quot;margin: 0px 3px 0px 0px; padding: 3px 10px 1px; font-size: inherit; line-height: inherit; display: inline-block; font-weight: normal; background: #EF7060; color: #FFFFFF; border-top-right-radius: 3px; border-top-left-radius: 3px;&quot;&gt;2. 如何保证消息幂等性，不被重复消费？&lt;/span&gt;&lt;/h3&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;其实，这个问题也算是 MQ 面试当中经常考察的一点，因为无论是什么 MQ 都会有这个问题。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;首先通过上边我们了解了什么是“幂等性”，以及 MQ 幂等性问题的产生，所以我们要清楚为什么会出现重复性消费？在什么场景会出现重复消费？&lt;/p&gt;&lt;h4 id=&quot;h-1&quot; style=&quot;margin: 1.6em 0px; padding: 0px; color: inherit; line-height: inherit; font-size: 1.2em; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;解决方法&lt;/span&gt;&lt;/h4&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;使用全局 MessageID 判断消费方使用同一个，解决幂等性问题。&lt;br style=&quot;margin: 0px; padding: 0px;&quot;/&gt;或者使用业务逻辑保证唯一（比如订单号码）&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;生产者关键代码：&lt;/strong&gt;&lt;/p&gt;&lt;pre highlighted=&quot;true&quot; has-selection=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;@Autowiredprivate&amp;nbsp;AmqpTemplate&amp;nbsp;amqpTemplate;/**
&amp;nbsp;*&amp;nbsp;发送消息
&amp;nbsp;*
&amp;nbsp;*&amp;nbsp;@param&amp;nbsp;queueName&amp;nbsp;队列名称
&amp;nbsp;*/public&amp;nbsp;void&amp;nbsp;send(String&amp;nbsp;queueName)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;&amp;quot;my_fanout_msg:&amp;quot;&amp;nbsp;+&amp;nbsp;System.currentTimeMillis();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Message&amp;nbsp;message&amp;nbsp;=&amp;nbsp;MessageBuilder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.withBody(msg.getBytes())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setContentType(MessageProperties.CONTENT_TYPE_JSON)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setContentEncoding(&amp;quot;utf-8&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setMessageId(UUID.randomUUID()&amp;nbsp;+&amp;nbsp;&amp;quot;&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.build();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(msg&amp;nbsp;+&amp;nbsp;&amp;quot;:&amp;quot;&amp;nbsp;+&amp;nbsp;msg);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;amqpTemplate.convertAndSend(queueName,&amp;nbsp;message);
}&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;如上，生产者在发送消息时（convertAndSend），给消息对象设置了唯一的 MessageID，只有该 MessageID 没有被消费者标记方能在重试机制中再次被消费。&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;消费者关键代码：&lt;/strong&gt;&lt;/p&gt;&lt;pre highlighted=&quot;true&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; transition-duration: 0.2s; transition-property: color, opacity; overflow: auto; color: rgb(62, 62, 62); font-size: 15px; letter-spacing: 2px; word-spacing: 2px; background-color: rgb(255, 255, 255);&quot;&gt;@RabbitListener(queues&amp;nbsp;=&amp;nbsp;&amp;quot;fanout_eamil_queue&amp;quot;)public&amp;nbsp;void&amp;nbsp;process(Message&amp;nbsp;message)&amp;nbsp;throws&amp;nbsp;Exception&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;revMessage&amp;nbsp;=&amp;nbsp;Thread.currentThread().getName()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;,邮件消费者获取生产者消息msg:&amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;new&amp;nbsp;String(message.getBody(),&amp;nbsp;&amp;quot;UTF-8&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;,messageId:&amp;quot;&amp;nbsp;+&amp;nbsp;message.getMessageProperties().getMessageId();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(revMessage);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;发送邮件的逻辑XXX
}&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px; padding: 15px 15px 15px 1rem; background: rgb(239, 235, 233); border-top: none; border-right: none; border-bottom: none; border-left: 5px solid rgb(239, 112, 96); border-image: initial; color: rgb(0, 0, 0); min-height: 20px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; letter-spacing: 2px; white-space: normal; word-spacing: 2px; line-height: inherit; font-size: 0.9em; overflow: auto; overflow-wrap: normal; word-break: normal;&quot;&gt;&lt;p style=&quot;margin-bottom: 0px; font-size: inherit; color: inherit; line-height: inherit;&quot;&gt;如上，通过&amp;nbsp;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;message.getMessageProperties().getMessageId()&lt;/strong&gt;&amp;nbsp;获取 MessageID，获取的 MessageID 可以用来判断是否已经被消费者消费过了，如果已经消费则取消再次消费。&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;&lt;strong style=&quot;margin: 0px; padding: 0px; font-size: inherit; line-height: inherit; color: rgb(233, 105, 0);&quot;&gt;通常怎么判断呢？&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 1.7em; margin-bottom: 1.7em; padding: 0px; color: inherit; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: inherit; letter-spacing: 2px; white-space: normal; word-spacing: 2px; background-color: rgb(255, 255, 255); line-height: inherit;&quot;&gt;比如上方是一个邮件发送的消费者，在做补偿时，假如上一步邮件发送成功了，我们会把该 ID 存至 redis中，下次再调用时，先去 redis 判断是否存在该 ID 了，如果存在表明已经消费过了则直接返回，不再消费，否则消费，然后将记录存至 redis。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 11 Mar 2021 13:56:17 +0800</pubDate></item><item><title>Centos6系统yum无法使用-最新解决办法</title><link>https://39dian.com/?id=50</link><description>&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin-top: 8px; margin-bottom: 16px; padding-top: 0px; padding-bottom: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;一、&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;CentOS6&lt;/code&gt;停止维护更新日期2020年11月30日&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/img_convert/9d84ba808f356d263186f397c6603b82.png&quot; alt=&quot;image-20201209121157897&quot; style=&quot;box-sizing: border-box; outline: none; border: 0px none; margin-top: 24px; margin-bottom: 24px; overflow-wrap: break-word; cursor: zoom-in;&quot;/&gt;&lt;/p&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin-top: 8px; margin-bottom: 16px; padding-top: 0px; padding-bottom: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t1&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a name=&quot;t1&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;2020122CentOS6_6&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;二、2020年12月2日下架了包括官方所有的&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;CentOS6&lt;/code&gt;源（包括国内的镜像站）&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/img_convert/7c91756b31980ba66cea45850350c479.png&quot; alt=&quot;image-20201209122255193&quot; style=&quot;box-sizing: border-box; outline: none; border: 0px none; margin-top: 24px; margin-bottom: 24px; overflow-wrap: break-word; cursor: zoom-in;&quot;/&gt;&lt;/p&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin-top: 8px; margin-bottom: 16px; padding-top: 0px; padding-bottom: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t2&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a name=&quot;t2&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;CentOS6_12&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;三、&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;CentOS6&lt;/code&gt;也完成了它的历史使命&lt;/h2&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;在生产的环境中依旧由很多CentOS6系统依然在坚持，那么可以采取挂载光盘或者使用centos-vault源安装软件包，这里挂载光盘的方式不做讲述。1&lt;/pre&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin-top: 8px; margin-bottom: 16px; padding-top: 0px; padding-bottom: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t3&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a name=&quot;t3&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;centosvault_20&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;四、使用&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;centos-vault&lt;/code&gt;作为更新源&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;1.官方地址&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;#阿里云http://mirrors.aliyun.com/centos-vault/#官方https://vault.centos.org/#阿里云和官方的任选其一即可1234567&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;2.使用阿里云&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;centos-vault&lt;/code&gt;源&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;vi&amp;nbsp;/etc/yum.repos.d/CentOS-Base.repo#&amp;nbsp;CentOS-Base.repo##&amp;nbsp;The&amp;nbsp;mirror&amp;nbsp;system&amp;nbsp;uses&amp;nbsp;the&amp;nbsp;connecting&amp;nbsp;IP&amp;nbsp;address&amp;nbsp;of&amp;nbsp;the&amp;nbsp;client&amp;nbsp;and&amp;nbsp;the#&amp;nbsp;update&amp;nbsp;status&amp;nbsp;of&amp;nbsp;each&amp;nbsp;mirror&amp;nbsp;to&amp;nbsp;pick&amp;nbsp;mirrors&amp;nbsp;that&amp;nbsp;are&amp;nbsp;updated&amp;nbsp;to&amp;nbsp;and#&amp;nbsp;geographically&amp;nbsp;close&amp;nbsp;to&amp;nbsp;the&amp;nbsp;client.&amp;nbsp;&amp;nbsp;You&amp;nbsp;should&amp;nbsp;use&amp;nbsp;this&amp;nbsp;for&amp;nbsp;CentOS&amp;nbsp;updates#&amp;nbsp;unless&amp;nbsp;you&amp;nbsp;are&amp;nbsp;manually&amp;nbsp;picking&amp;nbsp;other&amp;nbsp;mirrors.##&amp;nbsp;If&amp;nbsp;the&amp;nbsp;mirrorlist=&amp;nbsp;does&amp;nbsp;not&amp;nbsp;work&amp;nbsp;for&amp;nbsp;you,&amp;nbsp;as&amp;nbsp;a&amp;nbsp;fall&amp;nbsp;back&amp;nbsp;you&amp;nbsp;can&amp;nbsp;try&amp;nbsp;the#&amp;nbsp;remarked&amp;nbsp;out&amp;nbsp;baseurl=&amp;nbsp;line&amp;nbsp;instead.##[base]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Base&amp;nbsp;-&amp;nbsp;mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6#released&amp;nbsp;updates[updates]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Updates&amp;nbsp;-&amp;nbsp;mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6#additional&amp;nbsp;packages&amp;nbsp;that&amp;nbsp;may&amp;nbsp;be&amp;nbsp;useful[extras]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Extras&amp;nbsp;-&amp;nbsp;mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6#additional&amp;nbsp;packages&amp;nbsp;that&amp;nbsp;extend&amp;nbsp;functionality&amp;nbsp;of&amp;nbsp;existing&amp;nbsp;packages[centosplus]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Plus&amp;nbsp;-&amp;nbsp;mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6#contrib&amp;nbsp;-&amp;nbsp;packages&amp;nbsp;by&amp;nbsp;Centos&amp;nbsp;Users[contrib]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Contrib&amp;nbsp;-&amp;nbsp;mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-61234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;3.使用官方&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;centos-vault&lt;/code&gt;源&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;vi&amp;nbsp;/etc/yum.repos.d/CentOS-Base.repo#&amp;nbsp;CentOS-Base.repo##&amp;nbsp;The&amp;nbsp;mirror&amp;nbsp;system&amp;nbsp;uses&amp;nbsp;the&amp;nbsp;connecting&amp;nbsp;IP&amp;nbsp;address&amp;nbsp;of&amp;nbsp;the&amp;nbsp;client&amp;nbsp;and&amp;nbsp;the#&amp;nbsp;update&amp;nbsp;status&amp;nbsp;of&amp;nbsp;each&amp;nbsp;mirror&amp;nbsp;to&amp;nbsp;pick&amp;nbsp;mirrors&amp;nbsp;that&amp;nbsp;are&amp;nbsp;updated&amp;nbsp;to&amp;nbsp;and#&amp;nbsp;geographically&amp;nbsp;close&amp;nbsp;to&amp;nbsp;the&amp;nbsp;client.&amp;nbsp;&amp;nbsp;You&amp;nbsp;should&amp;nbsp;use&amp;nbsp;this&amp;nbsp;for&amp;nbsp;CentOS&amp;nbsp;updates#&amp;nbsp;unless&amp;nbsp;you&amp;nbsp;are&amp;nbsp;manually&amp;nbsp;picking&amp;nbsp;other&amp;nbsp;mirrors.##&amp;nbsp;If&amp;nbsp;the&amp;nbsp;mirrorlist=&amp;nbsp;does&amp;nbsp;not&amp;nbsp;work&amp;nbsp;for&amp;nbsp;you,&amp;nbsp;as&amp;nbsp;a&amp;nbsp;fall&amp;nbsp;back&amp;nbsp;you&amp;nbsp;can&amp;nbsp;try&amp;nbsp;the#&amp;nbsp;remarked&amp;nbsp;out&amp;nbsp;baseurl=&amp;nbsp;line&amp;nbsp;instead.##[base]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Base&amp;nbsp;-&amp;nbsp;vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6#released&amp;nbsp;updates[updates]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Updates&amp;nbsp;-&amp;nbsp;vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6#additional&amp;nbsp;packages&amp;nbsp;that&amp;nbsp;may&amp;nbsp;be&amp;nbsp;useful[extras]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Extras&amp;nbsp;-&amp;nbsp;vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6#additional&amp;nbsp;packages&amp;nbsp;that&amp;nbsp;extend&amp;nbsp;functionality&amp;nbsp;of&amp;nbsp;existing&amp;nbsp;packages[centosplus]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Plus&amp;nbsp;-&amp;nbsp;vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6#contrib&amp;nbsp;-&amp;nbsp;packages&amp;nbsp;by&amp;nbsp;Centos&amp;nbsp;Users[contrib]name=CentOS-6.10&amp;nbsp;-&amp;nbsp;Contrib&amp;nbsp;-&amp;nbsp;vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-61234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;4.替换&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;CentOS-Base.repo&lt;/code&gt;文件内容后清除下缓存&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;yum&amp;nbsp;clean&amp;nbsp;all&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;yum&amp;nbsp;makecache1&lt;/pre&gt;&lt;h2 style=&quot;box-sizing: border-box; outline: 0px; margin-top: 8px; margin-bottom: 16px; padding-top: 0px; padding-bottom: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t4&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a name=&quot;t4&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;epel_158&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;五、那么如何使用&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;epel&lt;/code&gt;源&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;1.官方地址&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;https://archives.fedoraproject.org/pub/archive/epel/1&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: common-ligatures; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;2.下载安装&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;epel&lt;/code&gt;源&lt;/p&gt;&lt;pre class=&quot;prettyprint&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px 16px 6px 56px; position: relative; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; overflow: auto hidden; border-bottom: 1px solid rgb(245, 246, 247); line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(250, 250, 250); z-index: 9; font-variant-ligatures: common-ligatures;&quot;&gt;#下载epel源wget&amp;nbsp;https://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm#安装epel源rpm&amp;nbsp;-ivh&amp;nbsp;epel-release-6-8.noarch.rpm#清除下缓存yum&amp;nbsp;clean&amp;nbsp;all&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;yum&amp;nbsp;makecache&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 31 Dec 2020 11:33:16 +0800</pubDate></item><item><title>解决 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 问题</title><link>https://39dian.com/?id=49</link><description>&lt;h3 id=&quot;问题症状&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;问题症状&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;最近把一部分服务迁移到用 rancher 管理的容器集群环境里面去了，感觉还是不错的，而且 rancher 里自带的负载均衡是 haproxy，配置上域名证书后由 haproxy 来负责 https 的处理，后端就不用配 https 了。服务跑起来之后，在日志中发现出现类似下面错误：&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;&lt;code style=&quot;font-family: Menlo, Consolas, monospace; font-size: 1.5rem; display: inline-block; padding: 0px 10px; background-color: rgb(247, 248, 248);&quot;&gt;javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;出现地方是在用 HttpClient 请求我们自己的 https 域名时报错，看起来是域名的证书没法验证通过。&lt;/p&gt;&lt;h3 id=&quot;问题初探&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;问题初探&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;网上搜索了之后发现有很多相关的内容，但是很多都是因为访问自签名证书的域名而产生的问题，给出的方案都是在代码里取消了对域名证书的验证。而我们的域名签名是有效的，不应该会出现这种问题，我们也不需要为了解决自签名证书去取消验证，所以药不对症，得继续寻找答案。&lt;/p&gt;&lt;h3 id=&quot;本地调试&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;本地调试&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;用 HttpClient 在本地写了简单的测试代码运行，发现同样报错，缩小了问题范围。&lt;strong&gt;关键点&lt;/strong&gt;：设置&amp;nbsp;&lt;code style=&quot;font-family: Menlo, Consolas, monospace; font-size: 1.5rem; display: inline-block; padding: 0px 10px; background-color: rgb(247, 248, 248);&quot;&gt;System.setProperty(&amp;quot;javax.net.debug&amp;quot;, &amp;quot;ssl&amp;quot;);&lt;/code&gt;&amp;nbsp;打开 ssl 的调试信息，可以获得相当多关键信息。在我的代码里，出错信息如下：&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;&lt;code style=&quot;font-family: Menlo, Consolas, monospace; font-size: 1.5rem; display: inline-block; padding: 0px 10px; background-color: rgb(247, 248, 248);&quot;&gt;handling exception: javax.net.ssl.SSLHandshakeException:Remote host closed connection during handshake&lt;/code&gt;&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;网上搜索了之后逐渐发现了关键问题所在： 域名证书是正常的，但 SSL 握手失败，判断是 JDK 使用的 SSL 协议和加密算法与我们的 WebServer 不匹配。&lt;/p&gt;&lt;h3 id=&quot;ssl-server-兼容性检查&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;SSL Server 兼容性检查&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;这里要祭出一个强力法器了&lt;a href=&quot;https://www.ssllabs.com/ssltest/&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;https://www.ssllabs.com/ssltest/&amp;nbsp;&lt;/a&gt;这个工具可以对域名的证书做详细的检查，更实用的功能是可以反馈各种 User Agent 访问的可用性，把我们的域名丢进去检测一下，得分 A 还不错，再仔细看看下面的列表…jdk6 jdk7 都显示无法连接…简直是个大悲剧。&lt;/p&gt;&lt;h3 id=&quot;谜底揭晓&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;谜底揭晓&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;这里涉及到 HTTPS 的几个概念，Protocols 和 Cipher Suites。一般来说，在给网站或应用做 SSL 加密时，Protocol 有以下几种：TLS1.2、TLS1.1、TLS1.0、SSLv3、SSLv2。不同的协议下使用的 Cipher Suites 也有不同。SSLv3 和 SSLv2由于前两年被爆出的严重安全漏洞，目前已经被认为不适合使用了，稍微新一点的 webserver 默认都是关闭这两项的，关键在于&amp;nbsp;&lt;strong&gt;TLS1.0&lt;/strong&gt;。通过上面那个检查 SSL 的网站发现我们的服务器（即 rancher 中的 haproxy），是只支持了 TLS1.2 和 TLS1.1 这两项的，实际上这也是现代服务器的推荐配置。&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;&lt;strong&gt;重点来了！&lt;/strong&gt;&amp;nbsp;jdk6 默认是只支持 TLS1.0 的，jdk7 支持 TLS1.1 和 TLS1.2 但是默认是不开启的，只有 jdk8 才默认选择最高的 TLS1.2。所以，只要是运行在 jdk6 和 jdk7 上，就有可能遇到这种问题。并且，我尝试了在 jdk7 中开启 TLS1.1 和 TLS1.2 的支持，但还是同样的错误，发现可能是由于我们的证书支持的 Cipher Suites 和 jdk7 中支持的对不上，还是验证失败。&lt;/p&gt;&lt;h3 id=&quot;解决方案&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px; font-size: 2.4rem;&quot;&gt;解决方案&lt;/h3&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;到这里怎么解决问题就比较清楚了，可以将部署了应用的 jetty 容器升级到 jdk8 的环境，继续使用 TLS1.2、TLS1.1 的配置组合即可。但是这样实际上还是放弃了对一部分旧 user agent 的支持，从上面那个检查的列表中来看，Android4.4 以下都是默认只支持 TLS1.0 的，所以出于更好的访问兼容性，还是打开对 TLS1.0 的支持比较好。&lt;/p&gt;&lt;h4 id=&quot;配置-rancher-中-haproxy-负载支持-tls1-0&quot; style=&quot;white-space: normal; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; letter-spacing: -0.04em; line-height: 1.45em; color: rgb(74, 74, 74); margin: 1em 0px 0.5em; font-size: 2.1rem;&quot;&gt;配置 Nginx支持 TLS1.0&lt;/h4&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;修改nginx配置&lt;/p&gt;&lt;p style=&quot;white-space: normal; margin-top: 1.5em; margin-bottom: 0px; caret-color: rgb(93, 104, 111); color: rgb(93, 104, 111); font-family: Merriweather, serif; font-size: 17px; letter-spacing: -0.30000001192092896px;&quot;&gt;&lt;span style=&quot;color: #FF0000; font-size: 16px; font-family: 微软雅黑, 宋体, Arial, Helvetica, sans-serif;&quot;&gt;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 16px; color: #FF0000;&quot;&gt;ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 16px; color: #FF0000;&quot;&gt;ssl_prefer_server_ciphers on;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 17 Mar 2020 11:47:05 +0800</pubDate></item><item><title>【国密SM2算法】创建密钥对、通过base64密钥串生成PublicKey和PrivateKey</title><link>https://39dian.com/?id=48</link><description>&lt;p&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px; color: #FF0000;&quot;&gt;&lt;strong&gt;&amp;nbsp;一：创建密钥对&lt;/strong&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;System.out.println(&amp;quot;----------生成秘钥对start----------------&amp;quot;);
//&amp;nbsp;引入BC库
Security.addProvider(new&amp;nbsp;BouncyCastleProvider());
//&amp;nbsp;获取SM2椭圆曲线的参数
final&amp;nbsp;ECGenParameterSpec&amp;nbsp;sm2Spec&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ECGenParameterSpec(&amp;quot;sm2p256v1&amp;quot;);
//&amp;nbsp;获取一个椭圆曲线类型的密钥对生成器
final&amp;nbsp;KeyPairGenerator&amp;nbsp;kpg&amp;nbsp;=&amp;nbsp;KeyPairGenerator.getInstance(&amp;quot;EC&amp;quot;,&amp;nbsp;new&amp;nbsp;BouncyCastleProvider());
//&amp;nbsp;使用SM2参数初始化生成器
kpg.initialize(sm2Spec);
//&amp;nbsp;使用SM2的算法区域初始化密钥生成器
kpg.initialize(sm2Spec,&amp;nbsp;new&amp;nbsp;SecureRandom());
//&amp;nbsp;获取密钥对
KeyPair&amp;nbsp;keyPair&amp;nbsp;=&amp;nbsp;kpg.generateKeyPair();
PublicKey&amp;nbsp;pk&amp;nbsp;=&amp;nbsp;keyPair.getPublic();
PrivateKey&amp;nbsp;privk=&amp;nbsp;keyPair.getPrivate();
System.out.println(&amp;quot;公钥串：&amp;quot;+new&amp;nbsp;BASE64Encoder().encode(keyPair.getPublic().getEncoded()));
System.out.println(&amp;quot;私钥串：&amp;quot;+new&amp;nbsp;BASE64Encoder().encode(keyPair.getPrivate().getEncoded()));
System.out.println(&amp;quot;公钥对象：&amp;quot;+pk);
System.out.println(&amp;quot;----------生成秘钥对end----------------&amp;quot;);&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 18px; color: #FF0000;&quot;&gt;&lt;strong&gt;二：解析公钥串生成publickey&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;------通过公钥串获取对象------&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;引入BC库
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Security.addProvider(new&amp;nbsp;BouncyCastleProvider());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;base64String&amp;nbsp;=
&amp;quot;MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAELTzwAJ1gWaUoBTm56qEKDwbwVlqMH8FSVqe2zfgajYK3w5gkq5MJAij3lODus99nWl/a9GnZC0HMC0Notc/RAw==&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;byte[]&amp;nbsp;publicBytes&amp;nbsp;=&amp;nbsp;new&amp;nbsp;BASE64Decoder().decodeBuffer(base64String);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X509EncodedKeySpec&amp;nbsp;eks&amp;nbsp;=&amp;nbsp;new&amp;nbsp;X509EncodedKeySpec(publicBytes);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;KeyFactory&amp;nbsp;kf&amp;nbsp;=&amp;nbsp;KeyFactory.getInstance(&amp;quot;EC&amp;quot;,&amp;nbsp;BouncyCastleProvider.PROVIDER_NAME);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ECPublicKey&amp;nbsp;bce2&amp;nbsp;=&amp;nbsp;(BCECPublicKey)&amp;nbsp;kf.generatePublic(eks);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(java.util.Base64.getEncoder().encodeToString(bce2.getEncoded()));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(hex16(publicBytes));&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 18px; color: #FF0000;&quot;&gt;&lt;strong&gt;三：&lt;strong style=&quot;caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); font-size: 18px; white-space: normal;&quot;&gt;解析私钥串生成privatekey&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-java&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;------通过私钥串获取对象------&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;引入BC库
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Security.addProvider(new&amp;nbsp;BouncyCastleProvider());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;&amp;nbsp;prvString&amp;nbsp;=
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgL5WougHVEKajECwDbW38fiDJMStq\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;Bn3VwxPxhZZPqvegCgYIKoEcz1UBgi2hRANCAASZZ6IKukES6ICKJYwZ9KeiUnMvJudW4+tyn2fl\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;xMMg0Urq8abPxXnIWGhIQvvjJZS/EcWwvKQQirzA7NVq4LYe&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;byte[]&amp;nbsp;prvBytes22&amp;nbsp;=&amp;nbsp;new&amp;nbsp;BASE64Decoder().decodeBuffer(prvString);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PKCS8EncodedKeySpec&amp;nbsp;eks2&amp;nbsp;=&amp;nbsp;new&amp;nbsp;PKCS8EncodedKeySpec(prvBytes22);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;KeyFactory&amp;nbsp;kf22=&amp;nbsp;KeyFactory.getInstance(&amp;quot;EC&amp;quot;,&amp;nbsp;BouncyCastleProvider.PROVIDER_NAME);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PrivateKey&amp;nbsp;pvk=&amp;nbsp;kf22.generatePrivate(eks2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BCECPrivateKey&amp;nbsp;bpve&amp;nbsp;=&amp;nbsp;(BCECPrivateKey)&amp;nbsp;pvk;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(&amp;quot;私钥：&amp;quot;+&amp;nbsp;bpve.getS()+&amp;quot;:::16hex:::&amp;quot;+bpve.getS().toString(16));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(hex16(prvBytes22));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bpve.getEncoded();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(hex16(bpve.getEncoded()));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println(pvk);&lt;/pre&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;</description><pubDate>Tue, 03 Mar 2020 17:29:34 +0800</pubDate></item><item><title>【国密SM2算法】通过公钥坐标XY获取PublicKey对象的两种方法</title><link>https://39dian.com/?id=47</link><description>&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;已知公钥坐标&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X：B5F2DC9B2C5EFB3329FE07FE3AE7D816E95CBECAFDD7F9E5D2AA73EC04C6C332&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Y：7F87AAEB592B531B668DE5C0D56B73D50D2C3102C2C0549A08E765A0B5D05DBE&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;strong&gt;方法一&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BigInteger X=new BigInteger(&amp;quot;B5F2DC9B2C5EFB3329FE07FE3AE7D816E95CBECAFDD7F9E5D2AA73EC04C6C332&amp;quot;,16);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BigInteger Y=new BigInteger(&amp;quot;7F87AAEB592B531B668DE5C0D56B73D50D2C3102C2C0549A08E765A0B5D05DBE&amp;quot;,16);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //载入bc库的支持&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(&amp;quot;sm2p256v1&amp;quot;); &amp;nbsp; &amp;nbsp; &amp;nbsp; //获取bc库内置曲线参数，曲线名称sm2p256v1&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECDomainParameters ecDomainParameters = new ECDomainParameters(spec.getCurve(),spec.getG(), spec.getN());&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; KeyFactory keyFactory= KeyFactory.getInstance(&amp;quot;EC&amp;quot;, BouncyCastleProvider.PROVIDER_NAME);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECCurve ecurve = ecDomainParameters.getCurve(); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//获取曲线对象&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECPoint q = ecurve.createPoint(X,Y); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//创建公钥点&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECParameterSpec ecps = new ECParameterSpec(ecurve,ecDomainParameters.getG(),ecDomainParameters.getN());&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECPublicKeySpec keySpec = new ECPublicKeySpec(q, ecps);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PublicKey pk= (ECPublicKey) keyFactory.generatePublic(keySpec);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;方法二&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;BigInteger X=new BigInteger(&amp;quot;B5F2DC9B2C5EFB3329FE07FE3AE7D816E95CBECAFDD7F9E5D2AA73EC04C6C332&amp;quot;,16);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BigInteger Y=new BigInteger(&amp;quot;7F87AAEB592B531B668DE5C0D56B73D50D2C3102C2C0549A08E765A0B5D05DBE&amp;quot;,16);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //载入bc库的支持&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(&amp;quot;sm2p256v1&amp;quot;); &amp;nbsp; &amp;nbsp; &amp;nbsp; //获取bc库内置曲线参数，曲线名称sm2p256v1&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECDomainParameters ecDomainParameters = new ECDomainParameters(spec.getCurve(),spec.getG(), spec.getN());&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; KeyFactory keyFactory= KeyFactory.getInstance(&amp;quot;EC&amp;quot;, BouncyCastleProvider.PROVIDER_NAME);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECCurve ecurve = ecDomainParameters.getCurve(); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//获取曲线对象&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECPoint q = ecurve.createPoint(X,Y); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//创建公钥点&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECParameterSpec ecps = new ECParameterSpec(ecurve,ecDomainParameters.getG(),ecDomainParameters.getN());&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ECPublicKeySpec keySpec = new ECPublicKeySpec(q, ecps);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt; PublicKey pk=new BCECPublicKey(&amp;quot;BC&amp;quot;,keySpec,BouncyCastleProvider.CONFIGURATION);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #F79646;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #F79646;&quot;&gt;&amp;nbsp; &amp;nbsp;方法一和方法二只有最后一句不同，前面都是为了获取曲线参数和创建坐标点。分开来写纯粹是为了凑点字数&lt;img src=&quot;https://39dian.com/zb_users/emotion/face/Smile.gif&quot;/&gt;&lt;img src=&quot;https://39dian.com/zb_users/emotion/face/Smile.gif&quot;/&gt;&lt;img src=&quot;https://39dian.com/zb_users/emotion/face/Smile.gif&quot;/&gt;&lt;/span&gt;&lt;/p&gt;</description><pubDate>Tue, 03 Mar 2020 11:42:15 +0800</pubDate></item></channel></rss><!--19.36 ms , 6 query , 2789kb memory , 1 error-->