Как правильно использовать конфигурацию SSL в HiveMQ Client? (MQTT) - PullRequest
0 голосов
/ 24 июня 2019

Я создал клиент для тестирования с использованием безопасного соединения и зашифрованной полезной нагрузки, поэтому я хотел использовать конфигурацию SSL по умолчанию.Я пытался сделать это, но я сразу получил ConnectionClosedException и сервер.Должен ли я что-то настраивать на сервере?Я оставил код и исключение внизу.

HiveMQ:

https://github.com/hivemq/hivemq-community-edition https://github.com/hivemq/hivemq-mqtt-client

Код:

    // 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)

1 Ответ

0 голосов
/ 14 июля 2019

Чтобы использовать Ssl-коммуникации, мне нужно было настроить сервер HiveMQ для работы с TLS. Сервер не поставляется предварительно настроенным и должен быть выполнен вручную. Я перешел по этой ссылке:

https://github.com/hivemq/hivemq-community-edition/wiki/HowTos#howto-configure-server-side-tls-with-hivemq-and-keytool-self-signed

...