HiveMQ

Client with same Identifier cannot subscribe sometimes

Hallo,

we have a Hivemq Client, it should subscribe to some Topic, but sometimes subscribtion doesn’t work if the client Identifier stays the same.

Mqtt5AsyncClient client = MqttClient.builder()
.identifier(springProfile + “-rp-hivemq-consumer”)
.serverHost(hivemqHost)
.serverPort(hivemqPort)
.useMqttVersion5()
.simpleAuth()
.username(username)
.password(password.getBytes(StandardCharsets.UTF_8))
.applySimpleAuth()
.automaticReconnectWithDefaultConfig()
.buildAsync();

  client.connectWith()
     .cleanStart(false)
     .noSessionExpiry()
     .send()
     .whenComplete((mqtt5ConnAck, throwable) -> {
        if (throwable != null) {
           LoggingHelper.error(LOG, this, "subscribeToBroker.connectWith", ArgsHelper.noArgs(), throwable,
              UUID.randomUUID().toString());
        } else {
           LoggingHelper.info(LOG, this, "subscribeToBroker.connectWith", ArgsHelper.getArgs(mqtt5ConnAck));
        }
     });

If i add some uuid to the identifier, it works fine. But with the same identifier, if i deploy the code newly, it could happen that the subscribtion doesn’t work . Could you give me some suggestion?

Thanks a lot
Best Regards,
Alex

Hi Alex,

it is great to see your interest in MQTT and HiveMQ client library! If a client with the same client id connects to the broker, the broker should disconnect that client that connected using this client id earlier.

Following questions could help to understand the issue that you are experiencing better:

  • When you deploy the code newly, are the previous instances of the client 100% offline?
  • What reconnect strategy your client has? For example, is it trying to reconnect at all times?
  • Is your client logging what is happening? (use log level TRACE for detailed logging)
  • When you are saying the subscription does not work, what do you actually see: an exception, an error or an info line in the logs?

Kind regards,
Dasha from HiveMQ Team

Hallo Dasha,

thanks for your reply. To your questions:

  • When you deploy the code newly, are the previous instances of the client 100% offline?
    Yes, the client is running in a docker container and by deployment the old container will be replaced by the new one
  • What reconnect strategy your client has? For example, is it trying to reconnect at all times?
    As the code above i use the automaticReconnectWithDefaultConfig, it am not sure but it should try to reconnect all times, all right?
  • Is your client logging what is happening? (use log level TRACE for detailed logging)
    I will try it
  • When you are saying the subscription does not work, what do you actually see: an exception, an error or an info line in the logs?
    There is no exception, but the client could not receive any Message.

Thanks a lot