Description
Expected Behavior
If there are two IntegrationFlow
s that use the same ClientFactory, to be able to share the same MQTT connection, hence being able to publish and subscribe with the same client id
Current Behavior
When I create two IntegartionFlow
s to publish & subscribe to an MQTT Broker, first the subscribe (inbound) flow connects and subscribes successfully to the given topic. Then when a message is published to a topic, the previous connection drops so the publishing (outbound) flow connects!
Relevant logs:
DEBUG 8950 --- [ main] .m.i.MqttPahoMessageDrivenChannelAdapter : Connected and subscribed to [notified]
INFO 8950 --- [ main] c.e.m.MqttSharedConnectionApplication : Publishing a message to MQTT Broker...
DEBUG 8950 --- [ main] o.s.i.m.outbound.MqttPahoMessageHandler : Client connected
ERROR 8950 --- [c: sameClientId] .m.i.MqttPahoMessageDrivenChannelAdapter : Lost connection: Connection lost; retrying...
DEBUG 8950 --- [ scheduling-1] .m.i.MqttPahoMessageDrivenChannelAdapter : Attempting reconnect
ERROR 8950 --- [c: sameClientId] o.s.i.m.outbound.MqttPahoMessageHandler : Lost connection; will attempt reconnect on next request
DEBUG 8950 --- [ scheduling-1] .m.i.MqttPahoMessageDrivenChannelAdapter : Connected and subscribed to [notified]
So basically they ping-pong with each other as MQTT allows only one connection per client id
Context
My use-case is that I have to use the same client id both for subscribing and publishing messages to the MQTT broker
Sample project: https://github.com/durimkryeziu/mqtt-shared-connection