mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-24 14:43:04 +08:00
Merge pull request #836 from PMExtra/develop
Support existing session with ManagedMqttClient.
This commit is contained in:
@@ -91,10 +91,6 @@ namespace MQTTnet.Extensions.ManagedClient
|
|||||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
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 == 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.");
|
if (!_maintainConnectionTask?.IsCompleted ?? false) throw new InvalidOperationException("The managed client is already started.");
|
||||||
|
|
||||||
@@ -333,6 +329,12 @@ namespace MQTTnet.Extensions.ManagedClient
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connectionState == ReconnectionResult.Recovered)
|
||||||
|
{
|
||||||
|
StartPublishing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (connectionState == ReconnectionResult.StillConnected)
|
if (connectionState == ReconnectionResult.StillConnected)
|
||||||
{
|
{
|
||||||
await PublishSubscriptionsAsync(Options.ConnectionCheckInterval, cancellationToken).ConfigureAwait(false);
|
await PublishSubscriptionsAsync(Options.ConnectionCheckInterval, cancellationToken).ConfigureAwait(false);
|
||||||
@@ -544,8 +546,8 @@ namespace MQTTnet.Extensions.ManagedClient
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _mqttClient.ConnectAsync(Options.ClientOptions).ConfigureAwait(false);
|
var result = await _mqttClient.ConnectAsync(Options.ClientOptions).ConfigureAwait(false);
|
||||||
return ReconnectionResult.Reconnected;
|
return result.IsSessionPresent ? ReconnectionResult.Recovered : ReconnectionResult.Reconnected;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
{
|
{
|
||||||
StillConnected,
|
StillConnected,
|
||||||
Reconnected,
|
Reconnected,
|
||||||
|
Recovered,
|
||||||
NotConnected
|
NotConnected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user