From a2414f48caf661015118f7dc525fefe5327d89ec Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 26 May 2019 23:44:42 +0200 Subject: [PATCH] Update Wiki samples. --- .../MainPage.xaml.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index 899ee21..f186bc4 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -733,6 +733,22 @@ namespace MQTTnet.TestApp.UniversalWindows var mqttServer = new MqttFactory().CreateMqttServer(); } + { + // Setup application message interceptor. + var options = new MqttServerOptionsBuilder() + .WithApplicationMessageInterceptor(context => + { + if (context.ApplicationMessage.Topic == "my/custom/topic") + { + context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes("The server injected payload."); + } + + // It is also possible to read the payload and extend it. For example by adding a timestamp in a JSON document. + // This is useful when the IoT device has no own clock and the creation time of the message might be important. + }) + .Build(); + } + { // Setup subscription interceptor. var options = new MqttServerOptionsBuilder()