Пример #1
0
        public static Task <MqttClientSubscribeResult> SubscribeAsync(this IMqttClient mqttClient, MqttTopicFilter topicFilter, CancellationToken cancellationToken = default)
        {
            if (mqttClient == null)
            {
                throw new ArgumentNullException(nameof(mqttClient));
            }

            if (topicFilter == null)
            {
                throw new ArgumentNullException(nameof(topicFilter));
            }

            var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topicFilter).Build();

            return(mqttClient.SubscribeAsync(subscribeOptions, cancellationToken));
        }
Пример #2
0
        public static Task <MqttClientSubscribeResult> SubscribeAsync(
            this IMqttClient mqttClient,
            string topic,
            MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
            CancellationToken cancellationToken             = default)
        {
            if (mqttClient == null)
            {
                throw new ArgumentNullException(nameof(mqttClient));
            }

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            var subscribeOptions = new MqttClientSubscribeOptionsBuilder().WithTopicFilter(topic, qualityOfServiceLevel).Build();

            return(mqttClient.SubscribeAsync(subscribeOptions, cancellationToken));
        }