Closed hzeng-tfs closed 1 month ago
I temporarily solved the issue by using two connections, one for publisher and one for subscriber to make sure they have different ClientId
s. This confirmed my observation.
Since a connection is allowed to have a publisher and a subscriber, I think it is a bug.
by the way, it could be nice to add an option to set ClientId
explicitly rather than using a random number only.
@hzeng-tfs Yes this is a bug, even the ClientId documentation states "Hint: This identifier needs to be unique over all used clients / devices on the broker to avoid connection issues."
Type of issue
Current Behavior
I built a MQTT client application which runs as a publisher and a subscriber at the same time. I follow the ConsoleReferencePublisher and ConsoleReferenceSubsciber basically. I added a few
WriterGroup
and aReaderGroup
to the the same connection.It runs correctly with a local Mosquitto server. However, I notice that there are lots of re-connection messages on log of Mosquitto:
On MQTT client side, the logs indicate that
SessionTakenOver
is the cause.Expected Behavior
the reconnection should not happen.
I debugged it a little and I think the cause of the issue is on the InternalStart() method of Opc.Ua.PubSub\Transport\MqttPubSubConnection.cs
Two
MqttClient
instances are created with sameClientId
(created onGetMqttClientOptions()
), one for publisher and one for subscriber. When two MQTT clients with sameClientId
connect to a broker, the broker just connects the new one and disconnect existing one.The 5s pattern on log file is caused by
private int m_reconnectIntervalSeconds = 5;
I think.So the potential fix:
MqttClient
instance for publisher and subscriber. (mqttMultimeter use one instance https://github.com/chkr1011/mqttMultimeter/blob/main/Source/Services/Mqtt/MqttClientService.cs )MqttClient
instances, one for each, but has differentClientId
Steps To Reproduce
No response
Environment
Anything else?
As I am still new on MQTT area, please let me know if there is an option to solve this behaviour or I did the coding wrong. Thanks.