dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.39k stars 1.05k forks source link

WithApplicationMessageInterceptor on v4 #2051

Open wootapa opened 1 month ago

wootapa commented 1 month ago

Trying to find the server event in version 4, that is the equivalent of what is mentioned here: https://github.com/dotnet/MQTTnet/issues/1467, but I cant find anything. I would like to intercept messages based on the receiving client. Could you give a hint?

SeppPenner commented 1 month ago

Take a look at https://github.com/dotnet/MQTTnet/blob/e18a91a4b59bc312aa9acf9be575401d07b793e4/Samples/Server/Server_Intercepting_Samples.cs#L16

wootapa commented 1 month ago

That's what I've used but InterceptingPublishAsync fires once per message. I would like to filter each message once per client, so I can reject based on client conditions. Possible?

SeppPenner commented 1 month ago

I'm not sure if this is possible...

Jeanot-Zubler commented 1 month ago

use server.InterceptingClientEnqueueAsync

wootapa commented 1 month ago

That's the one. Thanks. I also looked through the code to find a way to limit the retained messages upon subscription, but they seem filtered only based on the topic here MqttClientSubscription.FilterRetainedApplicationMessages https://github.com/dotnet/MQTTnet/blob/e18a91a4b59bc312aa9acf9be575401d07b793e4/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs#L462

It could possibly make sense to also have a hook here, basically doing the same thing as in server.InterceptingClientEnqueueAsync as a way to opt out for a specific message. What do you think?