您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ManagedMqttClientExtensions.cs 1.2 KiB

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Protocol;
  4. namespace MQTTnet.ManagedClient
  5. {
  6. public static class ManagedMqttClientExtensions
  7. {
  8. public static Task SubscribeAsync(this IManagedMqttClient managedClient, params TopicFilter[] topicFilters)
  9. {
  10. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  11. return managedClient.SubscribeAsync(topicFilters);
  12. }
  13. public static Task SubscribeAsync(this IManagedMqttClient managedClient, string topic, MqttQualityOfServiceLevel qualityOfServiceLevel)
  14. {
  15. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  16. if (topic == null) throw new ArgumentNullException(nameof(topic));
  17. return managedClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithQualityOfServiceLevel(qualityOfServiceLevel).Build());
  18. }
  19. public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params string[] topicFilters)
  20. {
  21. if (managedClient == null) throw new ArgumentNullException(nameof(managedClient));
  22. return managedClient.UnsubscribeAsync(topicFilters);
  23. }
  24. }
  25. }