mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-25 15:42:57 +08:00
dont allow publish before the client is started and adjusted testclient accordingly
This commit is contained in:
@@ -49,8 +49,6 @@ namespace MQTTnet.Extensions.ManagedClient
|
|||||||
|
|
||||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||||
_logger = logger.CreateChildLogger(nameof(ManagedMqttClient));
|
_logger = logger.CreateChildLogger(nameof(ManagedMqttClient));
|
||||||
|
|
||||||
Options = new ManagedMqttClientOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsConnected => _mqttClient.IsConnected;
|
public bool IsConnected => _mqttClient.IsConnected;
|
||||||
@@ -150,6 +148,7 @@ namespace MQTTnet.Extensions.ManagedClient
|
|||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
||||||
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
||||||
|
if (Options == null) throw new InvalidOperationException("call StartAsync before publishing messages");
|
||||||
|
|
||||||
MqttTopicValidator.ThrowIfInvalid(applicationMessage.ApplicationMessage.Topic);
|
MqttTopicValidator.ThrowIfInvalid(applicationMessage.ApplicationMessage.Topic);
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ namespace MQTTnet.TestApp.NetCore
|
|||||||
Console.WriteLine(">> RECEIVED: " + e.ApplicationMessage.Topic);
|
Console.WriteLine(">> RECEIVED: " + e.ApplicationMessage.Topic);
|
||||||
});
|
});
|
||||||
|
|
||||||
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("1"));
|
|
||||||
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("2").WithAtLeastOnceQoS());
|
|
||||||
|
|
||||||
await managedClient.StartAsync(options);
|
await managedClient.StartAsync(options);
|
||||||
|
|
||||||
|
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("1"));
|
||||||
|
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("2").WithAtLeastOnceQoS());
|
||||||
|
|
||||||
await managedClient.SubscribeAsync(new TopicFilter { Topic = "xyz", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
await managedClient.SubscribeAsync(new TopicFilter { Topic = "xyz", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||||
await managedClient.SubscribeAsync(new TopicFilter { Topic = "abc", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
await managedClient.SubscribeAsync(new TopicFilter { Topic = "abc", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user