public static IHealthChecksBuilder AddDependencies(
            this IHealthChecksBuilder builder,
            List <Dependency> dependencies)
        {
            foreach (var dependencia in dependencies)
            {
                string nomeDependencia = dependencia.Name.ToLower();

                if (nomeDependencia.StartsWith("sqlserver-"))
                {
                    builder = builder.AddSqlServer(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("mongodb-"))
                {
                    builder = builder.AddMongoDb(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("redis-"))
                {
                    builder = builder.AddRedis(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("postgres-"))
                {
                    builder = builder.AddNpgSql(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("mysql-"))
                {
                    builder = builder.AddMySql(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("url-"))
                {
                    builder = builder.AddUrlGroup(new Uri(dependencia.Url), name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("rabbitmq-"))
                {
                    builder = builder.AddRabbitMQ(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("azureservicebusqueue-"))
                {
                    builder = builder.AddAzureServiceBusQueue(dependencia.ConnectionString, queueName: dependencia.QueueName, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("azureblobstorage-"))
                {
                    builder = builder.AddAzureBlobStorage(dependencia.ConnectionString, name: dependencia.Name);
                }
                else if (nomeDependencia.StartsWith("documentdb-"))
                {
                    builder = builder.AddDocumentDb(
                        docdb => {
                        docdb.UriEndpoint = dependencia.UriEndpoint;
                        docdb.PrimaryKey  = dependencia.PrimaryKey;
                    });
                }
            }

            return(builder);
        }
Exemplo n.º 2
0
        public static IHealthChecksBuilder AddLiveCoordinationQueue(this IHealthChecksBuilder hcBuilder, ServiceBusSettings serviceBusSettings)
        {
            hcBuilder.AddAzureServiceBusQueue(
                serviceBusSettings.ConnectionString,
                serviceBusSettings.ServiceBusLiveQueueName,
                serviceBusSettings.ServiceBusLiveQueueName,
                tags: new[] { "servicebus" });

            return(hcBuilder);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add a health check for specified Azure Service Bus Queue.
 /// </summary>
 /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
 /// <param name="connectionString">The azure service bus connection string to be used.</param>
 /// <param name="queueName">The name of the queue to check.</param>
 /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azurequeue' will be used for the name.</param>
 /// <param name="failureStatus">
 /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
 /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
 /// </param>
 /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
 /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
 /// <returns>The specified <paramref name="builder"/>.</returns>
 public static IHealthChecksBuilder AddAzureServiceBusQueue(
     this IHealthChecksBuilder builder,
     string connectionString,
     string queueName,
     string?name = default,
     HealthStatus?failureStatus = default,
     IEnumerable <string>?tags  = default,
     TimeSpan?timeout           = default) =>
 builder.AddAzureServiceBusQueue(
     _ => connectionString,
     _ => queueName,
     name,
     failureStatus,
     tags,
     timeout);
Exemplo n.º 4
0
 /// <summary>
 /// Add a health check for specified Azure Service Bus Queue.
 /// </summary>
 /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
 /// <param name="endpoint">The azure service bus endpoint to be used, format sb://myservicebus.servicebus.windows.net/.</param>
 /// <param name="queueName">The name of the queue to check.</param>
 /// <param name="tokenCredential">The token credential for auth.</param>
 /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azurequeue' will be used for the name.</param>
 /// <param name="failureStatus">
 /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
 /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
 /// </param>
 /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
 /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
 /// <returns>The specified <paramref name="builder"/>.</returns>
 public static IHealthChecksBuilder AddAzureServiceBusQueue(
     this IHealthChecksBuilder builder,
     string endpoint,
     string queueName,
     TokenCredential tokenCredential,
     string?name = default,
     HealthStatus?failureStatus = default,
     IEnumerable <string>?tags  = default,
     TimeSpan?timeout           = default) =>
 builder.AddAzureServiceBusQueue(
     _ => endpoint,
     _ => queueName,
     _ => tokenCredential,
     name,
     failureStatus,
     tags,
     timeout);
        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);
        }