dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.51k stars 1.07k forks source link

Behavior of Managed Client and topic subscription #569

Closed VBMA closed 4 years ago

VBMA commented 5 years ago

Hi,

I ran into a problem with the managed client.

Following the scenario: 1 Broker 1 Managed client

Managed client did one subscription to a topic ex. "Topic1". Broker publishes a message to "Topic1" which was subscribed from the managed client. Managed client gets the message on "Topic1". At this point everything works fine.

Managed client does a second subscription to another topic ex. "Topic2". Managed client receives the same message which was already received to "Topic1".

On every new subscription we get new messages for the previous subscriptions with the same content.

Managed Client: Subscriptions -> "Topic1", "Topic2", "Topic3" Managed Client: New subscription -> "Topic4" Managed Client: Received messages for "Topic1" & "Topic2" & "Topic3" (Broker and client did not publish a massage to these topics at that moment.)

Why did I receive messages on all topics when we do a new subscription to another topic? Is this a behavior of the managed client?

I also tried this with a none managed client which does not show this behavior.

I thank you in advance for your help.

chkr1011 commented 5 years ago

Hi, yes this is correct (at the moment) because the managed client will send all subscriptions at the same time (which will lead to a receive of all matching retained messages). So you better subscribe to all topics at once.

But this is on the list for the next versions.

Best regards Christian

VBMA commented 5 years ago

Dear chkr1011,

thank you for your fast response. When can we expect a release of the next version which do not have this behavior in the managed client?

Best regards

cstichlberger commented 4 years ago

This issue has already been fixed with PR https://github.com/chkr1011/MQTTnet/pull/776 so IMO this issue can be closed as fixed.

SeppPenner commented 4 years ago

@cstichlberger Thank you for the udpate. Yes, this should be fixed already.