我正在尝试进行“可选”健康检查;和可以在用户界面中用来确定某个功能是否可见的端点。
所以在ConfigureServices
中,我是这样添加的:
.AddUrlGroup(new Uri(searchEngineConfig.Get<SearchEngineConfiguration>().Endpoint + SwaggerEndPoint), "Search API", failureStatus: HealthStatus.Degraded, tags: new string[] { "Optional", "Search" })
在Configure
中,我有这个
app.UseHealthChecks(HealthReadyEndPoint, new HealthCheckOptions()
{
Predicate = (check) => !check.Tags.Contains("Optional")
});
app.UseHealthChecks(HealthLiveEndPoint, new HealthCheckOptions()
{
Predicate = (check) => false,
});
app.UseHealthChecks(HealthSearchEndPoint, new HealthCheckOptions()
{
Predicate = (check) => check.Tags.Contains("Search")
});
基本上,它很好用;只有当搜索引擎在启动时不可用时,ASP.NET Core应用程序似乎才根本无法启动,并不断抛出“拒绝连接”错误。