public static IHealthChecksBuilder AddKafkaHealthCheck(this IHealthChecksBuilder services, IConfiguration configuration) { return(services.AddKafka(new AppKafkaOptions(configuration).ProducerConfig())); }
public static IServiceCollection AddMessageBusSender <T>(this IServiceCollection services, MessageBrokerOptions options, IHealthChecksBuilder healthChecksBuilder = null, HashSet <string> checkDulicated = null) { if (options.UsedRabbitMQ()) { services.AddRabbitMQSender <T>(options.RabbitMQ); if (healthChecksBuilder != null) { var name = "Message Broker (RabbitMQ)"; if (checkDulicated == null || !checkDulicated.Contains(name)) { healthChecksBuilder.AddRabbitMQ( rabbitMQConnectionString: options.RabbitMQ.ConnectionString, name: name, failureStatus: HealthStatus.Degraded); } checkDulicated?.Add(name); } } else if (options.UsedKafka()) { services.AddKafkaSender <T>(options.Kafka); if (healthChecksBuilder != null) { var name = "Message Broker (Kafka)"; if (checkDulicated == null || !checkDulicated.Contains(name)) { healthChecksBuilder.AddKafka( setup => { setup.BootstrapServers = options.Kafka.BootstrapServers; setup.MessageTimeoutMs = 5000; }, name: name, failureStatus: HealthStatus.Degraded); } checkDulicated?.Add(name); } } else if (options.UsedAzureQueue()) { services.AddAzureQueueSender <T>(options.AzureQueue); if (healthChecksBuilder != null) { healthChecksBuilder.AddAzureQueueStorage(connectionString: options.AzureQueue.ConnectionString, queueName: options.AzureQueue.QueueNames[typeof(T).Name], name: $"Message Broker (Azure Queue) {typeof(T).Name}", failureStatus: HealthStatus.Degraded); } } else if (options.UsedAzureServiceBus()) { services.AddAzureServiceBusSender <T>(options.AzureServiceBus); if (healthChecksBuilder != null) { healthChecksBuilder.AddAzureServiceBusQueue( connectionString: options.AzureServiceBus.ConnectionString, queueName: options.AzureServiceBus.QueueNames[typeof(T).Name], name: $"Message Broker (Azure Service Bus) {typeof(T).Name}", failureStatus: HealthStatus.Degraded); } } else if (options.UsedAzureEventGrid()) { services.AddAzureEventGridSender <T>(options.AzureEventGrid); // TODO: Add Health Check } else if (options.UsedAzureEventHub()) { services.AddAzureEventHubSender <T>(options.AzureEventHub); // TODO: Add Health Check } else if (options.UsedFake()) { services.AddFakeSender <T>(); } return(services); }