/// <summary> /// Setups the maintenance channel. /// </summary> private async void SetupMaintenanceConnection(Logger logger) { try { if (_maintenanceConnection == null || !_maintenanceConnection.IsConnected) { //setup maintenance connection logger.LogVerbose("Creating new maintenance connection"); //pick a random node from the list var strategy = new RandomConnectionStrategy(_nodes, _config); //get or create a connection var connection = strategy.GetOrCreateConnection(null); //allow this connection to be used by others as well _connectionSelector.ReturnConnection(connection); //setup event handlers connection.OnConnectionChange += (src, ev) => SetupMaintenanceConnection(logger); connection.OnClusterChange += OnClusterChange; //store the new connection _maintenanceConnection = connection; //register for events await connection.RegisterForClusterChangesAsync(logger).ConfigureAwait(false); logger.LogInfo("Registered for cluster changes using {0}", connection); } //all seems right, we're done return; } catch (Exception ex) { logger.LogWarning("Failed to setup maintenance connection: {0}", ex); //temporary disconnect or registration failed, reset maintenance connection _maintenanceConnection = null; } //wait a moment, try again logger.LogVerbose("Waiting 2secs before retrying setup maintenance connection"); await Task.Delay(2000).ConfigureAwait(false); SetupMaintenanceConnection(logger); }