async Task <MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync( IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection clientConnection, MqttApplicationMessage applicationMessage) { string senderClientId; IDictionary <object, object> sessionItems; var messageIsFromServer = clientConnection == null; if (messageIsFromServer) { senderClientId = _options.ClientId; sessionItems = _serverSessionItems; } else { senderClientId = clientConnection.ClientId; sessionItems = clientConnection.Session.Items; } var interceptorContext = new MqttApplicationMessageInterceptorContext { ClientId = senderClientId, SessionItems = sessionItems, AcceptPublish = true, ApplicationMessage = applicationMessage, CloseConnection = false }; await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false); return(interceptorContext); }
public MqttServerOptionsBuilder GetOptionsBuilder( IMqttServerSubscriptionInterceptor interceptor, IMqttServerApplicationMessageInterceptor messageInterceptor) { if (!int.TryParse(_configuration["Settings:Port"], out var port)) { port = 1883; } if (!int.TryParse(_configuration["Settings:SslPort"], out var sslport)) { sslport = 8883; } var optionsBuilder = new MqttServerOptionsBuilder() .WithDefaultEndpoint() .WithDefaultEndpointPort(port) .WithStorage(_storage) .WithPersistentSessions() .WithConnectionBacklog(15) //.WithEncryptionSslProtocol(SslProtocols.Tls) //.WithEncryptedEndpoint() //.WithEncryptedEndpointPort(sslport) .WithConnectionValidator(_validator) .WithSubscriptionInterceptor(interceptor) .WithApplicationMessageInterceptor(messageInterceptor); return(optionsBuilder); }
public MqttService( ILogger <MqttService> logger, IMqttServerSubscriptionInterceptor interceptor, IMqttServerApplicationMessageInterceptor messageInterceptor, IServiceProvider serviceProvider, IHostApplicationLifetime appLifetime) { _logger = logger; _interceptor = interceptor; _messageInterceptor = messageInterceptor; _serviceProvider = serviceProvider; _appLifetime = appLifetime; }
public MqttServerOptionsBuilder WithApplicationMessageInterceptor(IMqttServerApplicationMessageInterceptor value) { _options.ApplicationMessageInterceptor = value; return(this); }