mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-28 09:12:37 +08:00
Added IMqttRetainedMessagesManager
* Added interface IMqttRetainedMessagesManager to allow for different retained messages manager implementations. The interface copies almost exactly the current MqttRetainedMessagesManager implementation. * Added IMqttRetainedMessagesManager.Start() to configure the provided IMqttRetainedMessagesManager outside the constructor. This method returns Task because some implementations that use external storage may be slow on initialization (e.g., connect to a database). * Modified MqttRetainedMessagesManager to implement new interface.
This commit is contained in:
@@ -7,20 +7,21 @@ using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttRetainedMessagesManager
|
||||
public class MqttRetainedMessagesManager : IMqttRetainedMessagesManager
|
||||
{
|
||||
private readonly byte[] _emptyArray = new byte[0];
|
||||
private readonly AsyncLock _messagesLock = new AsyncLock();
|
||||
private readonly Dictionary<string, MqttApplicationMessage> _messages = new Dictionary<string, MqttApplicationMessage>();
|
||||
|
||||
private readonly IMqttNetChildLogger _logger;
|
||||
private readonly IMqttServerOptions _options;
|
||||
private IMqttNetChildLogger _logger;
|
||||
private IMqttServerOptions _options;
|
||||
|
||||
public MqttRetainedMessagesManager(IMqttServerOptions options, IMqttNetChildLogger logger)
|
||||
public Task Start(IMqttServerOptions options, IMqttNetChildLogger logger)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
_logger = logger.CreateChildLogger(nameof(MqttRetainedMessagesManager));
|
||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task LoadMessagesAsync()
|
||||
@@ -128,7 +129,7 @@ namespace MQTTnet.Server
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return matchingRetainedMessages;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user