java - 无法通过 ssl 连接到 mqtt 代理
问题描述
我有一个运行 mqtt 代理和 java 后端的树莓。因为我已经实现了 ssl,所以我无法建立从后端到代理的连接。我可以从 MacBook 上运行的 IDE 将后端连接到 raspberry 上的代理,例如:
client = new MqttAsyncClient(
"ssl://my-domain.com:1883", "backend");
如果后端在覆盆子上,我试过:
client = new MqttAsyncClient(
"ssl://localhost:1883", "backend");
client = new MqttAsyncClient(
"ssl://127.0.0.1:1883", "backend");
没有成功。在这种情况下,我从未使用过 ssl 连接。我监督了什么?
错误:
Exception in thread "main" No connection to client (32104)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:143)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:721)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:681)
at com.cdh.Service.mqttManager.subscribe(mqttManager.java:243)
at com.cdh.main.main(main.java:14)
编辑:
我将端口更改为 8883。如果我在其他设备上运行后端,它可以工作,但如果代理和后端在树莓上,则不能。我还尝试使用我的证书中的域名。
解决方案
The hostname you use to connect needs to match the CN or SAN entries in the certificate presented by the broker or else it will fail validation.
Unless you included 127.0.0.1
or localhost
in the certificate the the client will reject the connection because the certificate doesn't validate for that address.
p.s. you should probably use a different port for MQTT of TLS rather than 1883 as that is the standard port for MQTT without TLS.
推荐阅读
- streamsets - 无法在 StreamSets Data Collector 中从 Google Cloud Platform 读取数据
- php - 如何将日期从 2021 年 11 月 22 日转换为 2021 年 11 月 22 日
- html - 迁移到新的 Web 服务器后 WordPress 可视化作曲家错误
- android - 如何在 onCreate() 之外使用 ViewModel?
- android - OpenGL ES中的纹理采样精度问题
- python - 如何将数据存储备份转换为 JSON,包括地图和数组?
- libarchive - C++ 使用 libarchive 和 archive_write_open_memory ...如何清除缓冲区?
- sql - 我正在尝试使用“;”删除电子邮件 来自具有多封电子邮件的列的值
- dart - Dart 1 书籍是否仍然与学习 Dart 2 相关
- azure - Azure Function 3.0 Service Bus 触发有时会引发 Microsoft.Azure.ServiceBus.MessageLockLostException