mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Fix subscription handling of _ManagedClient_.
This commit is contained in:
@@ -45,6 +45,7 @@ namespace MQTTnet.ManagedClient
|
|||||||
public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
|
public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
|
||||||
public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
|
public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
|
||||||
public event EventHandler<ApplicationMessageProcessedEventArgs> ApplicationMessageProcessed;
|
public event EventHandler<ApplicationMessageProcessedEventArgs> ApplicationMessageProcessed;
|
||||||
|
public event EventHandler SynchronizingSubscriptionsFailed;
|
||||||
|
|
||||||
public async Task StartAsync(IManagedMqttClientOptions options)
|
public async Task StartAsync(IManagedMqttClientOptions options)
|
||||||
{
|
{
|
||||||
@@ -309,13 +310,22 @@ namespace MQTTnet.ManagedClient
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _mqttClient.SubscribeAsync(subscriptions).ConfigureAwait(false);
|
if (subscriptions.Any())
|
||||||
await _mqttClient.UnsubscribeAsync(unsubscriptions).ConfigureAwait(false);
|
{
|
||||||
|
await _mqttClient.SubscribeAsync(subscriptions).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unsubscriptions.Any())
|
||||||
|
{
|
||||||
|
await _mqttClient.UnsubscribeAsync(unsubscriptions).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
_logger.Warning<ManagedMqttClient>(exception, "Synchronizing subscriptions failed");
|
_logger.Warning<ManagedMqttClient>(exception, "Synchronizing subscriptions failed.");
|
||||||
_subscriptionsNotPushed = true;
|
_subscriptionsNotPushed = true;
|
||||||
|
|
||||||
|
SynchronizingSubscriptionsFailed?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user