internal async static Task AddListenerAsync(ConnectionMultiplexer multiplexer, ConnectionMultiplexer.LogProxy logProxy) { try { var sub = multiplexer.GetSubscriber(); if (sub == null) { logProxy?.WriteLine("Failed to GetSubscriber for AzureRedisEvents"); return; } await sub.SubscribeAsync(PubSubChannelName, async (channel, message) => { var newMessage = new AzureMaintenanceEvent(message); multiplexer.InvokeServerMaintenanceEvent(newMessage); switch (newMessage.NotificationType) { case AzureNotificationType.NodeMaintenanceEnded: case AzureNotificationType.NodeMaintenanceFailoverComplete: await multiplexer.ReconfigureAsync(first: false, reconfigureAll: true, log: logProxy, blame: null, cause: $"Azure Event: {newMessage.NotificationType}").ForAwait(); break; } }).ForAwait(); } catch (Exception e) { logProxy?.WriteLine($"Encountered exception: {e}"); } }
internal async static Task AddListenersAsync(ConnectionMultiplexer muxer, LogProxy logProxy) { if (!muxer.CommandMap.IsAvailable(RedisCommand.SUBSCRIBE)) { return; } if (muxer.RawConfig.IsAzureEndpoint()) { await AzureMaintenanceEvent.AddListenerAsync(muxer, logProxy).ForAwait(); } // Other providers could be added here later }
internal async static Task AddListenerAsync(ConnectionMultiplexer multiplexer, Action <string> log = null) { if (!multiplexer.CommandMap.IsAvailable(RedisCommand.SUBSCRIBE)) { return; } try { var sub = multiplexer.GetSubscriber(); if (sub == null) { log?.Invoke("Failed to GetSubscriber for AzureRedisEvents"); return; } await sub.SubscribeAsync(PubSubChannelName, async (_, message) => { var newMessage = new AzureMaintenanceEvent(message); newMessage.NotifyMultiplexer(multiplexer); switch (newMessage.NotificationType) { case AzureNotificationType.NodeMaintenanceEnded: case AzureNotificationType.NodeMaintenanceFailoverComplete: case AzureNotificationType.NodeMaintenanceScaleComplete: await multiplexer.ReconfigureAsync($"Azure Event: {newMessage.NotificationType}").ForAwait(); break; } }).ForAwait(); } catch (Exception e) { log?.Invoke($"Encountered exception: {e}"); } }