Add a method for clearing all retained messages at the server.

This commit is contained in:
Christian Kratky
2018-09-29 11:49:02 +02:00
parent 699cd5fc23
commit 56a1530cee
4 changed files with 19 additions and 0 deletions
+2
View File
@@ -11,7 +11,9 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker).</description> <description>MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker).</description>
<releaseNotes>* [Core] Added all factory methods to the factory interface. <releaseNotes>* [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 new overload for configuring the ASP.net integration (thanks to @JanEggers).
* [Server] Added a method for clearing all retained messages.
</releaseNotes> </releaseNotes>
<copyright>Copyright Christian Kratky 2016-2018</copyright> <copyright>Copyright Christian Kratky 2016-2018</copyright>
<tags>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</tags> <tags>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</tags>
+2
View File
@@ -23,5 +23,7 @@ namespace MQTTnet.Server
Task StartAsync(IMqttServerOptions options); Task StartAsync(IMqttServerOptions options);
Task StopAsync(); Task StopAsync();
Task ClearRetainedMessagesAsync();
} }
} }
@@ -84,6 +84,16 @@ namespace MQTTnet.Server
return retainedMessages; return retainedMessages;
} }
public Task ClearMessagesAsync()
{
lock (_messages)
{
_messages.Clear();
}
return _options.Storage.SaveRetainedMessagesAsync(new List<MqttApplicationMessage>());
}
private async Task HandleMessageInternalAsync(string clientId, MqttApplicationMessage applicationMessage) private async Task HandleMessageInternalAsync(string clientId, MqttApplicationMessage applicationMessage)
{ {
var saveIsRequired = false; var saveIsRequired = false;
+5
View File
@@ -129,6 +129,11 @@ namespace MQTTnet.Server
} }
} }
public Task ClearRetainedMessagesAsync()
{
return _retainedMessagesManager?.ClearMessagesAsync();
}
internal void OnClientConnected(string clientId) internal void OnClientConnected(string clientId)
{ {
_logger.Info("Client '{0}': Connected.", clientId); _logger.Info("Client '{0}': Connected.", clientId);