Add interceptor for client subscriptions

This commit is contained in:
Christian Kratky
2017-10-28 10:34:25 +02:00
parent d0f1c18a2f
commit ba16ae6568
11 changed files with 140 additions and 66 deletions
+4 -6
View File
@@ -35,16 +35,14 @@ namespace MQTTnet.TestApp.NetCore
options.Storage = new RetainedMessageHandler();
options.ApplicationMessageInterceptor = message =>
options.ApplicationMessageInterceptor = context =>
{
if (MqttTopicFilterComparer.IsMatch(message.Topic, "/myTopic/WithTimestamp/#"))
if (MqttTopicFilterComparer.IsMatch(context.ApplicationMessage.Topic, "/myTopic/WithTimestamp/#"))
{
// Replace the payload with the timestamp. But also extending a JSON
// based payload with the timestamp is a suitable use case.
message.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
}
return message;
context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
}
};
});