1

After the MQTTv5 client is reconnected successfully, it does not re-subscribe to the topics. I am unable to retrieve messages unless I reboot my application.

Spring Boot version: 3.0.2 MQTT integration version: 6.0.2

Here is the sample I am using:

@Configuration
class MnpConfiguration {
    
    @Bean
    fun mqttInputChannel(): MessageChannel {
        return DirectChannel()
    }

    @Bean
    fun clientManager(): ClientManager<IMqttAsyncClient, MqttConnectionOptions> {
        val connectionOptions = MqttConnectionOptions()
        connectionOptions.serverURIs = arrayOf("mqtt://localhost:1883")
        connectionOptions.connectionTimeout = 3000
        connectionOptions.maxReconnectDelay = 1000
        connectionOptions.isAutomaticReconnect = true
      
        val clientManager = Mqttv5ClientManager(connectionOptions, UUID.randomUUID().toString())
        return clientManager
    }

    @Bean
    fun inbound(): MessageProducer {
        val manager = clientManager()

        val adapter = Mqttv5PahoMessageDrivenChannelAdapter(
            manager,
            "TEST"
        )

        adapter.setCompletionTimeout(1000)
        adapter.setPayloadType(String::class.java)
        adapter.setQos(0)
        adapter.outputChannel = mqttInputChannel()

        return adapter
    }
}
@Component
class MnpStream {

    @Bean
    @ServiceActivator(inputChannel = "mqttInputChannel")
    fun handleMnpLicense() = MessageHandler {
        println(String(it.payload as ByteArray))
    }
}

When I try to add my custom callback that calls the adapter.connectComplete(false), the subscribers are re-subscribed and everything seems to work fine.

manager.addCallback {
   if (it && !adapter.connectionInfo.isCleanStart) {
       adapter.connectComplete(false)
   }
}

Any help is welcome :)

iamceph
  • 11
  • 4

1 Answers1

0

Any chances to have a simple project from you to reproduce? Well, I see what you mean that we don't react for a connectComplete(true) what happens from the client in case of reconnect and we don't resubscrbier, but see here: https://github.com/eclipse/paho.mqtt.java/issues/493. So, it is really possible that you are not lucky enough to have that subscription persisted for your cleanStart = false.

Well, I believe that your can open a new GH issue and we always perform resubscribe on every reconnect.

We probably don't have a respective test about loosing connection in the middle, so we never checked if we receive messages after successful reconnection...

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 1
    Hi, thank you for your response. I created the sample repo here: https://github.com/iamceph/spring-integration-mqtt-bug I will create new GitHub issue shortly after. – iamceph Feb 10 '23 at 13:10
  • The mentioned GH issue: https://github.com/spring-projects/spring-integration/issues/8550 – Artem Bilan Feb 10 '23 at 14:21