소스 검색

Add new server option to disable/enable persistent sessions.

release/3.x.x
Christian 6 년 전
부모
커밋
719838de3b
4개의 변경된 파일30개의 추가작업 그리고 1개의 파일을 삭제
  1. +3
    -0
      Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs
  2. +19
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs
  3. +2
    -1
      Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs
  4. +6
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs

+ 3
- 0
Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs 파일 보기

@@ -5,6 +5,9 @@ namespace MQTTnet.Server
public interface IMqttServerOptions
{
int ConnectionBacklog { get; }

bool EnablePersistentSessions { get; }

int MaxPendingMessagesPerClient { get; }
MqttPendingMessagesOverflowStrategy PendingMessagesOverflowStrategy { get; }



+ 19
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs 파일 보기

@@ -107,6 +107,11 @@ namespace MQTTnet.Server
_logger.Error(exception, exception.Message);
}

if (!_options.EnablePersistentSessions)
{
await DeleteSessionAsync(clientId).ConfigureAwait(false);
}

Server.OnClientDisconnected(new ConnectedMqttClient
{
ClientId = clientId,
@@ -224,6 +229,20 @@ namespace MQTTnet.Server
return context.ReturnCode;
}

private async Task DeleteSessionAsync(string clientId)
{
await _sessionsLock.EnterAsync(CancellationToken.None);
try
{
_sessions.Remove(clientId);
_logger.Verbose("Session for client '{0}' deleted.", clientId);
}
finally
{
_sessionsLock.Exit();
}
}

private async Task<GetOrCreateClientSessionResult> PrepareClientSessionAsync(MqttConnectPacket connectPacket)
{
await _sessionsLock.EnterAsync(CancellationToken.None).ConfigureAwait(false);


+ 2
- 1
Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs 파일 보기

@@ -8,10 +8,11 @@ namespace MQTTnet.Server

public MqttServerTlsEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsEndpointOptions();

public bool EnablePersistentSessions { get; set; }

public int ConnectionBacklog { get; set; } = 10;

public int MaxPendingMessagesPerClient { get; set; } = 250;

public MqttPendingMessagesOverflowStrategy PendingMessagesOverflowStrategy { get; set; } = MqttPendingMessagesOverflowStrategy.DropOldestQueuedMessage;

public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(15);


+ 6
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs 파일 보기

@@ -103,6 +103,12 @@ namespace MQTTnet.Server
return this;
}

public MqttServerOptionsBuilder WithPersistentSessions()
{
_options.EnablePersistentSessions = true;
return this;
}

public IMqttServerOptions Build()
{
return _options;


불러오는 중...
취소
저장