public static IHealthChecksBuilder AddLiveCompetitionsTopic(this IHealthChecksBuilder hcBuilder, ServiceBusSettings serviceBusSettings) { hcBuilder.AddAzureServiceBusTopic( serviceBusSettings.ConnectionString, serviceBusSettings.ServiceBusLiveCompetitionsTopicName, serviceBusSettings.ServiceBusLiveCompetitionsTopicName, tags: new[] { "servicebus" }); return(hcBuilder); }
public static IHealthChecksBuilder AddAzureServiceBusTopic(this IHealthChecksBuilder healthChecksBuilder, IConfiguration configuration, string name = "az-servicebus-check") { healthChecksBuilder .AddAzureServiceBusTopic( configuration["EventBusConnectionHC"], // this connection string can't contains the EntityPath (topic name) topicName: "duber_event_bus", name, tags: new string[] { "az-servicebus" }); return(healthChecksBuilder); }
/// <summary> /// Add a health check for Azure Service Bus Topic. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="connectionString">The Azure ServiceBus connection string to be used.</param> /// <param name="topicName">The topic name of the topic to check.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azuretopic' 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 AddAzureServiceBusTopic( this IHealthChecksBuilder builder, string connectionString, string topicName, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) => builder.AddAzureServiceBusTopic( _ => connectionString, _ => topicName, name, failureStatus, tags, timeout);
/// <summary> /// Add a health check for Azure Service Bus Topic. /// </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="topicName">The topic name of the topic 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 'azuretopic' 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 AddAzureServiceBusTopic( this IHealthChecksBuilder builder, string endpoint, string topicName, TokenCredential tokenCredential, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) => builder.AddAzureServiceBusTopic( _ => endpoint, _ => topicName, _ => tokenCredential, name, failureStatus, tags, timeout);
//public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) //{ // services.AddApplicationInsightsTelemetry(configuration); // //string orchestratorType = configuration.GetValue<string>("OrchestratorType"); // //if (orchestratorType?.ToUpper() == "K8S") // //{ // // // Enable K8s telemetry initializer // // services.EnableKubernetes(); // //} // //if (orchestratorType?.ToUpper() == "SF") // //{ // // // Enable SF telemetry initializer // // services.AddSingleton<ITelemetryInitializer>((serviceProvider) => // // new FabricTelemetryInitializer()); // //} // return services; //} public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) { string accountName = configuration.GetValue <string>("AzureStorageAccountName"); string accountKey = configuration.GetValue <string>("AzureStorageAccountKey"); string name = configuration.GetValue <string>("HealthCheck:Name"); IHealthChecksBuilder hcBuilder = services.AddHealthChecks(); if (!string.IsNullOrEmpty(name)) { hcBuilder .AddCheck(name, () => HealthCheckResult.Healthy()); } bool bDb = configuration.GetValue <bool>("HealthCheck:DB:Enable"); if (bDb) { string hcname = configuration.GetValue <string>("HealthCheck:DB:Name"); string[] tags = configuration.GetSection("HealthCheck:DB:tags").Get <string[]>(); hcBuilder .AddSqlServer( configuration["ConnectionString"], name: hcname, tags: tags); } bool bStorage = configuration.GetValue <bool>("HealthCheck:AzureBlobStorage:Enable"); if (bStorage && !string.IsNullOrEmpty(accountName) && !string.IsNullOrEmpty(accountKey)) { string hcname = configuration.GetValue <string>("HealthCheck:AzureBlobStorage:Name"); string[] tags = configuration.GetSection("HealthCheck:AzureBlobStorage:tags").Get <string[]>(); hcBuilder .AddAzureBlobStorage( $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accountKey};EndpointSuffix=core.windows.net", name: hcname, tags: tags); } bool bService = configuration.GetValue <bool>("HealthCheck:AzureServiceBusTopic:Enable"); if (bService && configuration.GetValue <bool>("AzureServiceBusEnabled")) { string hcname = configuration.GetValue <string>("HealthCheck:AzureServiceBusTopic:Name"); string topic = configuration.GetValue <string>("HealthCheck:AzureServiceBusTopic:topicName"); string[] tags = configuration.GetSection("HealthCheck:AzureServiceBusTopic:tags").Get <string[]>(); hcBuilder .AddAzureServiceBusTopic( configuration["EventBusConnection"], topicName: topic, name: hcname, tags: tags); } bool bRabbit = configuration.GetValue <bool>("HealthCheck:RabbitMQ:Enable"); if (bRabbit && !configuration.GetValue <bool>("AzureServiceBusEnabled")) { string hcname = configuration.GetValue <string>("HealthCheck:RabbitMQ:Name"); string[] tags = configuration.GetSection("HealthCheck:RabbitMQ:tags").Get <string[]>(); hcBuilder .AddRabbitMQ( $"amqp://{configuration["EventBusConnection"]}", name: hcname, tags: tags); } return(services); }
public static IHealthChecksBuilder AddCustomAzureServiceBusTopic(this IHealthChecksBuilder builder, IConfiguration configuration) { var connectionString = new ServiceBusConnectionStringBuilder(configuration.GetAzureServiceBusConnectionString()); return(builder.AddAzureServiceBusTopic(connectionString.GetNamespaceConnectionString(), connectionString.EntityPath)); }