public MqttClientSubscribeOptionsBuilder WithTopicFilter(MqttTopicFilterBuilder topicFilterBuilder) { if (topicFilterBuilder == null) { throw new ArgumentNullException(nameof(topicFilterBuilder)); } return(WithTopicFilter(topicFilterBuilder.Build())); }
public async Task Subscribe(string topic, int qos = 0) { var subscribe = new MqttTopicFilterBuilder().WithTopic(topic); subscribe.WithAtMostOnceQoS(); var topicfilter = subscribe.Build(); dicSubscribe.AddOrUpdate(topic, topicfilter, (k, v) => topicfilter); await mqttClient.SubscribeAsync(topicfilter); }
public MqttClientService(IMqttClient mqttClient, IMqttClientOptions options, string[] topics) { _mqttClient = mqttClient; _options = options; MqttTopicFilterBuilder topicFilterBuilder = new MqttTopicFilterBuilder(); for (int i = 0; i < topics.Length; i++) { topicFilterBuilder.WithTopic(topics[i]); } _topicFilter = topicFilterBuilder.Build(); }
private async Task SubscribeAsync(string topic) { var tfb = new MqttTopicFilterBuilder() .WithTopic(topic) .WithAtMostOnceQoS(); var build = tfb.Build(); var opts = new MqttClientSubscribeOptionsBuilder() .WithTopicFilter(build); await this.Client.SubscribeAsync(opts.Build(), CancellationToken.None); this._logger.LogInformation($"Subscribed to: {topic}"); }