Java 如何在HiveMQ客户端中正确使用SSL配置?(MQTT)
我创建了一个客户端来使用安全连接和加密负载进行测试,所以我想使用默认的SSL配置。我试图这样做,但我得到了一个Java 如何在HiveMQ客户端中正确使用SSL配置?(MQTT),java,mqtt,hivemq,Java,Mqtt,Hivemq,我创建了一个客户端来使用安全连接和加密负载进行测试,所以我想使用默认的SSL配置。我试图这样做,但我得到了一个连接closedexception,服务器立即关闭。我应该在服务器上配置一些东西吗?我在下面留下了代码和异常 HiveMQ: 代码: // Creates the client object using Blocking API subscriber = Mqtt5Client.builder() .identifier(UUID.randomUUID()
连接closedexception
,服务器立即关闭。我应该在服务器上配置一些东西吗?我在下面留下了代码和异常
HiveMQ:
代码:
// Creates the client object using Blocking API
subscriber = Mqtt5Client.builder()
.identifier(UUID.randomUUID().toString()) // the unique identifier of the MQTT client. The ID is randomly generated between
.serverHost("localhost") // the host name or IP address of the MQTT server. Kept it localhost for testing. localhost is default if not specified.
.serverPort(1883) // specifies the port of the server
.addConnectedListener(context -> ClientConnectionRetreiver.printConnected("Subscriber1")) // prints a string that the client is connected
.addDisconnectedListener(context -> ClientConnectionRetreiver.printDisconnected("Subscriber1")) // prints a string that the client is disconnected
.sslWithDefaultConfig()
.buildBlocking(); // creates the client builder
subscriber.connect();
例外情况:
com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT.
at com.hivemq.client.internal.mqtt.MqttBlockingClient.connect(MqttBlockingClient.java:91)
at com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient.connect(Mqtt5BlockingClient.java:64)
at com.main.SubThread.run(SubThread.java:71)
at java.base/java.lang.Thread.run(Thread.java:834)
为了使用Ssl通信,我需要将HiveMQ服务器设置为使用TLS。服务器不是预先配置的,必须手动完成。我点击了这个链接:
是吗?@LutzHorn,我没有。你能给我一些提示或指导吗?我一直在看。我似乎找不到关于在服务器上设置TLS的解释。请查看我的第一条评论中的链接。这基本上是一个只包含链接的答案,一旦链接断开,这将变得毫无用处。请确保答案实际包含相关信息,且链接仅供参考。