Просмотр исходного кода

Merge pull request #836 from PMExtra/develop

Support existing session with ManagedMqttClient.
release/3.x.x
Christian 5 лет назад
committed by GitHub
Родитель
Сommit
7b25c6f274
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
2 измененных файлов: 9 добавлений и 6 удалений
  1. +8
    -6
      Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs
  2. +1
    -0
      Source/MQTTnet.Extensions.ManagedClient/ReconnectionResult.cs

+ 8
- 6
Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs Просмотреть файл

@@ -91,10 +91,6 @@ namespace MQTTnet.Extensions.ManagedClient
if (options == null) throw new ArgumentNullException(nameof(options));
if (options.ClientOptions == null) throw new ArgumentException("The client options are not set.", nameof(options));

if (!options.ClientOptions.CleanSession)
{
throw new NotSupportedException("The managed client does not support existing sessions.");
}

if (!_maintainConnectionTask?.IsCompleted ?? false) throw new InvalidOperationException("The managed client is already started.");

@@ -333,6 +329,12 @@ namespace MQTTnet.Extensions.ManagedClient
return;
}

if (connectionState == ReconnectionResult.Recovered)
{
StartPublishing();
return;
}

if (connectionState == ReconnectionResult.StillConnected)
{
await PublishSubscriptionsAsync(Options.ConnectionCheckInterval, cancellationToken).ConfigureAwait(false);
@@ -544,8 +546,8 @@ namespace MQTTnet.Extensions.ManagedClient

try
{
await _mqttClient.ConnectAsync(Options.ClientOptions).ConfigureAwait(false);
return ReconnectionResult.Reconnected;
var result = await _mqttClient.ConnectAsync(Options.ClientOptions).ConfigureAwait(false);
return result.IsSessionPresent ? ReconnectionResult.Recovered : ReconnectionResult.Reconnected;
}
catch (Exception exception)
{


+ 1
- 0
Source/MQTTnet.Extensions.ManagedClient/ReconnectionResult.cs Просмотреть файл

@@ -4,6 +4,7 @@
{
StillConnected,
Reconnected,
Recovered,
NotConnected
}
}

Загрузка…
Отмена
Сохранить