private void ClientDisconnected(object clientSession, ClientSessionDisconnectedEventArgs eventArgs) { _logger.LogInformation("Broker client disconnected from server"); OnDisconnected?.Invoke(this, new ClientDisconnectedEventArgs()); // check if auto reconnect is enabled if (_configuration.AutoReconnect) { _logger.LogInformation("Trying to reconnect broker client"); Reconnect(); } }
private void ClientDisconnected(object clientSession, ClientSessionDisconnectedEventArgs eventArgs) { if (clientSession is IClient client) { _logger.LogInformation($"Client: {client.Id} removed"); foreach (var queue in _topicStore.GetAll()) { queue.ClientUnsubscribed(client); } _clientStore.Remove(client); } }
/// <inheritdoc /> public void Close() { // we need to lock the close method // otherwise multiple concurrent calls to Close will cause the OnDisconnected to be called twice lock (this) { if (IsClosed) { return; } try { _logger.LogInformation($"Dispose was called on client: {Id}"); // mark as disposed IsClosed = true; // complete the channel _queue.Writer.TryComplete(); // cancelling the receive cancellation token _cancellationTokenSource.Cancel(); // setting status for all the tickets SetStatusForAllPendingTickets(); // disconnect the socket if (_socket.Connected) { _socket.Disconnect(); } // we need to invoice OnDisconnected on a separate thread ThreadPool.QueueUserWorkItem(_ => { var disconnectedEventArgs = new ClientSessionDisconnectedEventArgs { Id = Id }; OnDisconnected?.Invoke(this, disconnectedEventArgs); OnDisconnected = null; }); } catch { // no-op } } }