diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c59abca..2dbe731 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -11,7 +11,9 @@ false MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). * [Core] Added all factory methods to the factory interface. +* [Core] Fixed an issue with cancellation token handling (thanks to @acrabb). * [Server] Added a new overload for configuring the ASP.net integration (thanks to @JanEggers). +* [Server] Added a method for clearing all retained messages. Copyright Christian Kratky 2016-2018 MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin diff --git a/Source/MQTTnet/Server/IMqttServer.cs b/Source/MQTTnet/Server/IMqttServer.cs index e724a65..55ba710 100644 --- a/Source/MQTTnet/Server/IMqttServer.cs +++ b/Source/MQTTnet/Server/IMqttServer.cs @@ -23,5 +23,7 @@ namespace MQTTnet.Server Task StartAsync(IMqttServerOptions options); Task StopAsync(); + + Task ClearRetainedMessagesAsync(); } } \ No newline at end of file diff --git a/Source/MQTTnet/Server/MqttRetainedMessagesManager.cs b/Source/MQTTnet/Server/MqttRetainedMessagesManager.cs index 6a515a1..c2c8eb0 100644 --- a/Source/MQTTnet/Server/MqttRetainedMessagesManager.cs +++ b/Source/MQTTnet/Server/MqttRetainedMessagesManager.cs @@ -84,6 +84,16 @@ namespace MQTTnet.Server return retainedMessages; } + public Task ClearMessagesAsync() + { + lock (_messages) + { + _messages.Clear(); + } + + return _options.Storage.SaveRetainedMessagesAsync(new List()); + } + private async Task HandleMessageInternalAsync(string clientId, MqttApplicationMessage applicationMessage) { var saveIsRequired = false; diff --git a/Source/MQTTnet/Server/MqttServer.cs b/Source/MQTTnet/Server/MqttServer.cs index 6d53291..4086b18 100644 --- a/Source/MQTTnet/Server/MqttServer.cs +++ b/Source/MQTTnet/Server/MqttServer.cs @@ -129,6 +129,11 @@ namespace MQTTnet.Server } } + public Task ClearRetainedMessagesAsync() + { + return _retainedMessagesManager?.ClearMessagesAsync(); + } + internal void OnClientConnected(string clientId) { _logger.Info("Client '{0}': Connected.", clientId);