mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-11-01 19:54:07 +08:00
Expose server session items (#1638)
* Expose server session items * Add support for custom session items for injected application messages
This commit is contained in:
@@ -28,8 +28,6 @@ namespace MQTTnet.Server
|
||||
readonly MqttRetainedMessagesManager _retainedMessagesManager;
|
||||
readonly IMqttNetLogger _rootLogger;
|
||||
|
||||
readonly IDictionary _sessionItems = new ConcurrentDictionary<object, object>();
|
||||
|
||||
CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
public MqttServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger)
|
||||
@@ -167,6 +165,12 @@ namespace MQTTnet.Server
|
||||
|
||||
public bool IsStarted => _cancellationTokenSource != null;
|
||||
|
||||
/// <summary>
|
||||
/// Gives access to the session items which belong to this server. This session items are passed
|
||||
/// to several events instead of the client session items if the event is caused by the server instead of a client.
|
||||
/// </summary>
|
||||
public IDictionary ServerSessionItems { get; } = new ConcurrentDictionary<object, object>();
|
||||
|
||||
public Task DeleteRetainedMessagesAsync()
|
||||
{
|
||||
ThrowIfNotStarted();
|
||||
@@ -228,9 +232,11 @@ namespace MQTTnet.Server
|
||||
throw new NotSupportedException("Injected application messages must contain a topic. Topic alias is not supported.");
|
||||
}
|
||||
|
||||
var sessionItems = injectedApplicationMessage.CustomSessionItems ?? ServerSessionItems;
|
||||
|
||||
return _clientSessionsManager.DispatchApplicationMessage(
|
||||
injectedApplicationMessage.SenderClientId,
|
||||
_sessionItems,
|
||||
sessionItems,
|
||||
injectedApplicationMessage.ApplicationMessage,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user