使用此Enterprise HealthChecks for ASP.NET Core Diagnostics Package时,我遇到了一个问题,即HealtChecks告诉我我的端点不正常,而实际上一切正常。
我现在得到的错误消息(将Nuget软件包更新为5.5.2之后)是
[2019-07-17 11:25:16.147 +02:00 Error]
[HealthChecks.UI.Core.HostedService.HealthCheckReportCollector] []
GetHealthReport threw an exception when trying to get report from
http://url.domain/health configured with name {name}.
System.Net.Http.HttpRequestException: An error occurred while sending the
request. ---> System.IO.IOException: Unable to read data from the transport
connection: An existing connection was forcibly closed by the remote host. ---
> System.Net.Sockets.SocketException: An existing connection was forcibly
closed by the remote host
还有
[2019-07-17 11:25:16.482 +02:00 Error]
[MassTransit.RabbitMqTransport.Transport.RabbitMqReceiveTransport] [] RabbitMQ
Connect Failed: "Operation interrupted"
我的启动配置:
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env)
{
app.UseHealthChecks("/health", new HealthCheckOptions
{
Predicate = check => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
}).UseHealthChecksUI(setup =>
{
setup.ApiPath = "/healthchecks-api";
setup.UIPath = "/healthchecks-ui";
});
app.UseMvc();
OnServiceConfiguration(services);
}
public override void OnServiceConfiguration(IServiceCollection services)
{
services.AddMassTransit(x =>
{
x.AddConsumer<MailConsumer>();
x.AddConsumer<MailFailedConsumer>();
x.AddBus(provider => ConfigureBus(provider,
rabbitMqConfigurations));
});
services.AddMassTransitHostedService();
}
private IBusControl ConfigureBus(
IServiceProvider provider,
RabbitMqSettings rabbitMqConfigurations) =>
Bus.Factory.CreateUsingRabbitMq(
cfg =>
{
var host = cfg.Host(
rabbitMqConfigurations.Host,
"/",
hst => {
hst.Username(rabbitMqConfigurations.Username);
hst.Password(rabbitMqConfigurations.Password);
});
cfg.UseHealthCheck(provider);
cfg.ReceiveEndpoint(host, $"{typeof(MailSent).Namespace}.{typeof(MailSent).Name}", endpoint =>
{
endpoint.Consumer<MailConsumer>(provider);
});
cfg.ReceiveEndpoint(host, $"{typeof(MailSentFailed).Namespace}.{typeof(MailSentFailed).Name}", endpoint =>
{
endpoint.Consumer<MailFailedConsumer>(provider);
});
});
当我不使用消费者时,HealthCheck就可以了。端点有问题,但是什么呢?