0

I have working code similar to this connecting to google IoT with the paho client.

Since I am in a spring boot reactive application, I would like to use Hive MQTT Client, but I can't find the right setup, I keep having the following error message :

com.hivemq.client.mqtt.exceptions.ConnectionClosedException: Server closed connection without DISCONNECT.

The current code I use :

    hiveClient = MqttClient.builder()
            .identifier(UUID.randomUUID().toString())
            .serverHost("mqtt.googleapis.com")
            .serverPort(443)
            .useMqttVersion3()
            .sslWithDefaultConfig()
            .simpleAuth(
                    Mqtt3SimpleAuth.builder()
                            .username("unused")
                            .password(StandardCharsets.UTF_8.encode("// a token string generation that works fine with palo"))
                            .build()
            )
            .build()
            .toBlocking();
    hiveClient.connect(); // Error
Ismail
  • 1,068
  • 1
  • 6
  • 11
Raphaël Lemaire
  • 1,269
  • 1
  • 13
  • 23

1 Answers1

0

It looks like the identifier (client ID) should be set to something other than a UUID. The documentation indicates the client ID should be formed as the following path:

projects/PROJECT_ID/locations/REGION/registries/REGISTRY_ID/devices/DEVICE_ID

Note that all of the requirements for the Google Cloud IoT Core MQTT device bridge are strict, so also verify that Hive is configured as follows:

  • Mqtt 3.1.1
  • TLS 1.2
  • Publish to /devices/DEVICE_ID/events or /devices/DEVICE_ID/state
  • Subscribe to /devices/DEVICE_ID/config or /devices/DEVICE_ID/commands/#
  • QoS 0 or 1

Note that if you do not adhere to the requirements, your device gets disconnected. Additional information on the disconnect reason may be available in the logging for your registry visible on the Cloud Console for IoT.

class
  • 8,621
  • 29
  • 30