1

I have a spring boot (v. 3.0.5) project using spring-integration-mqtt (v. 6.0.4) and also use paho mqttv5 client. I want to setup a shared subscription via the ClientManager and the Integration DSL. But I cannot get it to work.

@Bean
fun clientManager(): ClientManager<IMqttAsyncClient, MqttConnectionOptions> {
    val connectionOptions = MqttConnectionOptions()
    connectionOptions.serverURIs = arrayOf("tcp://example.org:1883")
    
    val clientManager = Mqttv5ClientManager(connectionOptions, "testClient")
    clientManager.setPersistence(MqttDefaultFilePersistence())
    return clientManager
}

@Bean
fun mqttTestInFlow(clientManager: ClientManager<IMqttAsyncClient, MqttConnectionOptions>): IntegrationFlow {
    val messageProducer = Mqttv5PahoMessageDrivenChannelAdapter(
        clientManager,
        "\$share/testGroup/foo/test",
    )

    return IntegrationFlow.from(messageProducer)
        .channel("mqttInputChannel")
        .get()
}

@ServiceActivator(inputChannel = "mqttInputChannel")
fun handler(message: Message<String>) {
    println("Received message: ${message.payload}")
}

I can see in the logs from my mosquitto broker that the subscription is created and also that messages published to foo/test are published to the testClient (the spring service). But my handler never receives these messages. When I remove the $share/testGroup from the topic string then everything works just fine.

protenhan
  • 35
  • 8
  • And what is that `$share/testGroup`? Why do we need it? – Artem Bilan Apr 06 '23 at 16:14
  • I want to subscribe to a shared subscription as specified here https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901250 – protenhan Apr 06 '23 at 16:54
  • Yeah... It looks like this feature doesn't work well with Paho client: https://github.com/eclipse/paho.mqtt.java/issues/367. Thank you for sharing! We may try to investigate it more and find some workaround – Artem Bilan Apr 06 '23 at 17:22
  • Here is more in this blog post: https://yogin16.github.io/2017/07/15/mqtt-shared-sub-with-paho/ – Artem Bilan Apr 06 '23 at 17:27
  • Thank you for your help. We will try to work without shared subscriptions for now. But may come back to this at some point. – protenhan Apr 11 '23 at 06:53

0 Answers0