【问题标题】:How can I store the Circuit Breaker state into the database?如何将断路器状态存储到数据库中?
【发布时间】:2020-03-03 14:40:39
【问题描述】:

我必须在我的应用程序中实现断路器。一切正常,断路器正在工作,但我需要将其状态存储到数据库中。我怎样才能做到这一点?我在网上找不到任何可靠的东西。

这是用于断路器的代码:

public static IServiceCollection AddTenantService(this
IServiceCollection services, IConfiguration configuration)
        {
            var tenantServiceSettings = configuration?.GetSection("ApiEndpoints");
            var tenantServiceBaseUrl = tenantServiceSettings.GetValue<string>("TenantServiceApiLink");

            var advancedCircuitBreakerPolicy = Policy
                .HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)
                .AdvancedCircuitBreakerAsync(0.5, TimeSpan.FromSeconds(30), 2, 
                    TimeSpan.FromSeconds(30), onBreak: (exception, context) => Console.WriteLine($"{exception}"), onReset: null);
 
            services.AddHttpClient<ITenantService, TenantService>(client => { client.BaseAddress = new
Uri(tenantServiceBaseUrl); })
                .SetHandlerLifetime(TimeSpan.FromMinutes(5))
                .AddPolicyHandler(advancedCircuitBreakerPolicy);
            return services;
        }

谢谢!

【问题讨论】:

    标签: c# api polly circuit-breaker


    【解决方案1】:

    Polly 没有提供将断路器状态存储在数据库中的机制。


    Polly 团队编写了一个持久(即持久)分布式断路器,可在此处找到:https://github.com/Polly-Contrib/Polly.Contrib.AzureFunctions.CircuitBreaker

    这种持久的分布式断路器作为持久实体函数托管在 Azure Functions 中。 (您自己获取代码并将其托管在自己的 Azure Functions 实例中。)

    可以消耗耐用的分布式断路器:

    • 在 Azure 函数应用程序中 - 通过普通 Azure 函数或持久编排函数;
    • 从任何地方,通过 https API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 2011-11-05
      • 2019-11-08
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多