Add the ClientId to the application message interceptor.

This commit is contained in:
Christian Kratky
2017-12-11 17:10:27 +01:00
parent fb8b60fccc
commit f91d935708
4 changed files with 17 additions and 9 deletions
+1
View File
@@ -20,6 +20,7 @@
* [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!).
* [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). * [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan).
* [Client] Added an overload for subscribing at both clients which reduces required code. * [Client] Added an overload for subscribing at both clients which reduces required code.
* [Client] Added the _ClientId_ to the application message interceptor context.
* [Server] The application message interceptor can now delete any received application message. * [Server] The application message interceptor can now delete any received application message.
* [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki).
* [Server] Added an interface for the _MqttServerOptions_. * [Server] Added an interface for the _MqttServerOptions_.
@@ -2,6 +2,14 @@
{ {
public class MqttApplicationMessageInterceptorContext public class MqttApplicationMessageInterceptorContext
{ {
public MqttApplicationMessageInterceptorContext(string clientId, MqttApplicationMessage applicationMessage)
{
ClientId = clientId;
ApplicationMessage = applicationMessage;
}
public string ClientId { get; }
public MqttApplicationMessage ApplicationMessage { get; set; } public MqttApplicationMessage ApplicationMessage { get; set; }
} }
} }
@@ -136,7 +136,7 @@ namespace MQTTnet.Server
{ {
try try
{ {
applicationMessage = InterceptApplicationMessage(applicationMessage); applicationMessage = InterceptApplicationMessage(senderClientSession, applicationMessage);
if (applicationMessage == null) if (applicationMessage == null)
{ {
return; return;
@@ -168,17 +168,16 @@ namespace MQTTnet.Server
} }
} }
private MqttApplicationMessage InterceptApplicationMessage(MqttApplicationMessage applicationMessage) private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage)
{ {
if (_options.ApplicationMessageInterceptor == null) if (_options.ApplicationMessageInterceptor == null)
{ {
return applicationMessage; return applicationMessage;
} }
var interceptorContext = new MqttApplicationMessageInterceptorContext var interceptorContext = new MqttApplicationMessageInterceptorContext(
{ senderClientSession.ClientId,
ApplicationMessage = applicationMessage applicationMessage);
};
_options.ApplicationMessageInterceptor(interceptorContext); _options.ApplicationMessageInterceptor(interceptorContext);
return interceptorContext.ApplicationMessage; return interceptorContext.ApplicationMessage;