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.4k stars 1.06k forks source link

how to unsubscibe all topics #2063

Open lujiashun1 opened 1 month ago

lujiashun1 commented 1 month ago

MqttTest.zip github `var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()

            .Build();
        //MqttClientUnsubscribeOptions mqttClientUnsubscribeOptions = new MqttClientUnsubscribeOptions();
        //mqttClientUnsubscribeOptions.TopicFilters = mqttClient.Options.
        //await mqttClient.UnsubscribeAsync(mqttClientUnsubscribeOptions);
        mqttSubscribeOptions.TopicFilters = mqttTopicFilters;

        var response = await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);`

when I click Subscribe several times,I received several identical messages at the same time, Can't it remove duplicate topics,or how to unsbuscribe all topics?

SeppPenner commented 3 weeks ago

You can subsribe to the same topic multiple times if you want, but you shouldn't. And you can unsubscribe using UnsubscribeAsync, so what's the point?