public async Task OnConnectionLostAsync(IMqttPersisterConnection connection, MqttClientConnectionEventArgs args) { if (args != null && args.IsReConnected) { if (args.DisconnectReason == Client.Disconnecting.MqttClientDisconnectReason.NormalDisconnection) { await ReSubscribeAllAsync(); } } }
private Task InvokeClientConnectionChangedMethod(MqttClientConnectionEventArgs args) { var handler = ClientConnectionChanged; if (handler != null) { return(handler.Invoke(this, args)); } return(Task.CompletedTask); }
private Task OnConnectedAsync(MqttClientConnectedEventArgs e) { if (_disconnectionCache.TryGetValue(_options.ClientId, out var args)) { if (!args.IsReConnected) { _logger.LogInformation($"A MqttServer '{_options.ClientId}' trying to connect..."); args.MarkAsConnected(); return(InvokeClientConnectionChangedMethod(args)); } } else { _disconnectionCache.Add(_options.ClientId, MqttClientConnectionEventArgs.Connected(_options.ClientId)); } return(Task.CompletedTask); }
private async Task OnDisconnectedAsync(MqttClientDisconnectedEventArgs e) { if (_disposed) { return; } _logger.LogWarning($"A MqttServer '{_options.ClientId}' connection is shutdown, Reason: {e.Reason}. Trying to re-connect..."); if (_disconnectionCache.TryGetValue(_options.ClientId, out var args)) { if (args.IsReConnected) { args.MarkAsDisconnected(); await InvokeClientConnectionChangedMethod(args); } } else { _disconnectionCache.Add(_options.ClientId, MqttClientConnectionEventArgs.Disconnected(_options.ClientId, e.Reason)); await InvokeClientConnectionChangedMethod(args); } await TryConnectAsync(true); }