public MqttClientConnection( MqttConnectPacket connectPacket, IMqttChannelAdapter channelAdapter, MqttClientSession session, IMqttServerOptions serverOptions, MqttClientSessionsManager sessionsManager, IMqttRetainedMessagesManager retainedMessagesManager, Func <Task> onStart, Func <MqttClientDisconnectType, Task> onStop, IMqttNetLogger logger) { Session = session ?? throw new ArgumentNullException(nameof(session)); _serverOptions = serverOptions ?? throw new ArgumentNullException(nameof(serverOptions)); _sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager)); _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); _onStart = onStart ?? throw new ArgumentNullException(nameof(onStart)); _onStop = onStop ?? throw new ArgumentNullException(nameof(onStop)); _channelAdapter = channelAdapter ?? throw new ArgumentNullException(nameof(channelAdapter)); _dataConverter = _channelAdapter.PacketFormatterAdapter.DataConverter; _endpoint = _channelAdapter.Endpoint; ConnectPacket = connectPacket ?? throw new ArgumentNullException(nameof(connectPacket)); if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttClientConnection)); _keepAliveMonitor = new MqttClientKeepAliveMonitor(ConnectPacket.ClientId, () => StopAsync(), _logger); _connectedTimestamp = DateTime.UtcNow; _lastPacketReceivedTimestamp = _connectedTimestamp; _lastNonKeepAlivePacketReceivedTimestamp = _lastPacketReceivedTimestamp; }
public void Setup() { _logger = new MqttNetLogger("1"); _childLogger = _logger.CreateChildLogger("child"); MqttNetGlobalLogger.LogMessagePublished += OnLogMessagePublished; }
public MqttServer(IEnumerable <IMqttServerAdapter> adapters, IMqttNetLogger logger) { if (adapters == null) { throw new ArgumentNullException(nameof(adapters)); } _adapters = adapters.ToList(); if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttServer)); _eventDispatcher = new MqttServerEventDispatcher(logger.CreateChildLogger(nameof(MqttServerEventDispatcher))); }
public MqttTcpServerAdapter(IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttTcpServerAdapter)); }
public MqttClient(IMqttClientAdapterFactory channelFactory, IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _adapterFactory = channelFactory ?? throw new ArgumentNullException(nameof(channelFactory)); _logger = logger.CreateChildLogger(nameof(MqttClient)); }
public Task Start(IMqttServerOptions options, IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttRetainedMessagesManager)); _options = options ?? throw new ArgumentNullException(nameof(options)); return(PlatformAbstractionLayer.CompletedTask); }
public ManagedMqttClient(IMqttClient mqttClient, IMqttNetLogger logger) { _mqttClient = mqttClient ?? throw new ArgumentNullException(nameof(mqttClient)); if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(ManagedMqttClient)); }
public IMqttServer CreateMqttServer(IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } return(CreateMqttServer(new List <IMqttServerAdapter> { new MqttTcpServerAdapter(logger.CreateChildLogger()) }, logger)); }
public MqttClientKeepAliveMonitor(string clientId, Func <Task> keepAliveElapsedCallback, IMqttNetLogger logger) { _clientId = clientId ?? throw new ArgumentNullException(nameof(clientId)); _keepAliveElapsedCallback = keepAliveElapsedCallback ?? throw new ArgumentNullException(nameof(keepAliveElapsedCallback)); if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttClientKeepAliveMonitor)); }
public static IManagedMqttClient CreateManagedMqttClient(this IMqttClientFactory factory, IMqttNetLogger logger) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } return(new ManagedMqttClient(factory.CreateMqttClient(), logger.CreateChildLogger())); }
public IMqttServer CreateMqttServer(IEnumerable <IMqttServerAdapter> serverAdapters, IMqttNetLogger logger) { if (serverAdapters == null) { throw new ArgumentNullException(nameof(serverAdapters)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } return(new MqttServer(serverAdapters, logger.CreateChildLogger())); }
public MqttChannelAdapter(IMqttChannel channel, MqttPacketFormatterAdapter packetFormatterAdapter, IMqttNetLogger logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _channel = channel ?? throw new ArgumentNullException(nameof(channel)); PacketFormatterAdapter = packetFormatterAdapter ?? throw new ArgumentNullException(nameof(packetFormatterAdapter)); _packetReader = new MqttPacketReader(_channel); _logger = logger.CreateChildLogger(nameof(MqttChannelAdapter)); }
public LowLevelMqttClient(IMqttClientAdapterFactory clientAdapterFactory, IMqttNetLogger logger) { if (clientAdapterFactory is null) { throw new ArgumentNullException(nameof(clientAdapterFactory)); } if (logger is null) { throw new ArgumentNullException(nameof(logger)); } _clientAdapterFactory = clientAdapterFactory; _logger = logger.CreateChildLogger(nameof(LowLevelMqttClient)); }
public MqttClientSession(string clientId, IDictionary <object, object> items, MqttServerEventDispatcher eventDispatcher, IMqttServerOptions serverOptions, IMqttRetainedMessagesManager retainedMessagesManager, IMqttNetLogger logger) { ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId)); Items = items ?? throw new ArgumentNullException(nameof(items)); _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); SubscriptionsManager = new MqttClientSubscriptionsManager(this, eventDispatcher, serverOptions); ApplicationMessagesQueue = new MqttClientSessionApplicationMessagesQueue(serverOptions); if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttClientSession)); }
private static IMqttServer CreateOrleansMqttSever(this MqttFactory factory, IClusterClient clusterClient, IMqttServerOptions options, IMqttNetLogger logger, ILogger <OrleansManagedMqttServer> appLogger) { if (clusterClient == null) { throw new ArgumentNullException(nameof(clusterClient)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } return(CreateOrleansMqttSever(factory, clusterClient, options, new List <IMqttServerAdapter> { new MqttTcpServerAdapter(logger.CreateChildLogger()) }, logger, appLogger)); }
public MqttTcpServerListener( AddressFamily addressFamily, MqttServerTcpEndpointBaseOptions options, X509Certificate2 tlsCertificate, IMqttNetLogger logger) { _addressFamily = addressFamily; _options = options; _tlsCertificate = tlsCertificate; _logger = logger.CreateChildLogger(nameof(MqttTcpServerListener)); if (_options is MqttServerTlsTcpEndpointOptions tlsOptions) { _tlsOptions = tlsOptions; } }
public MqttClientSessionsManager( IMqttServerOptions options, IMqttRetainedMessagesManager retainedMessagesManager, CancellationToken cancellationToken, MqttServerEventDispatcher eventDispatcher, IMqttNetLogger logger) { _cancellationToken = cancellationToken; if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger.CreateChildLogger(nameof(MqttClientSessionsManager)); _eventDispatcher = eventDispatcher ?? throw new ArgumentNullException(nameof(eventDispatcher)); _options = options ?? throw new ArgumentNullException(nameof(options)); _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); }
public async Task RunWebSocketConnectionAsync(WebSocket webSocket, HttpContext httpContext) { if (webSocket == null) { throw new ArgumentNullException(nameof(webSocket)); } var endpoint = $"{httpContext.Connection.RemoteIpAddress}:{httpContext.Connection.RemotePort}"; var clientCertificate = await httpContext.Connection.GetClientCertificateAsync().ConfigureAwait(false); try { var isSecureConnection = clientCertificate != null; var clientHandler = ClientHandler; if (clientHandler != null) { var writer = new SpanBasedMqttPacketWriter(); var formatter = new MqttPacketFormatterAdapter(writer); var channel = new MqttWebSocketChannel(webSocket, endpoint, isSecureConnection, clientCertificate); using (var channelAdapter = new MqttChannelAdapter(channel, formatter, _logger.CreateChildLogger(nameof(MqttWebSocketServerAdapter)))) { await clientHandler(channelAdapter).ConfigureAwait(false); } } } finally { clientCertificate?.Dispose(); } }
public MqttHostedServerEx(IMqttServerOptions options, IEnumerable <IMqttServerAdapter> adapters, IMqttNetLogger logger) : base(adapters, logger.CreateChildLogger(nameof(MqttHostedServerEx))) { Options = options ?? throw new ArgumentNullException(nameof(options)); }