mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 02:53:06 +08:00
Add a method for clearing all retained messages at the server.
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user