This is my health check code for RabbitMQ.
import {
Controller,
Get
} from '@nestjs/common';
import {
RmqOptions,
Transport
} from '@nestjs/microservices';
import {
HealthCheck,
HealthCheckService,
HttpHealthIndicator,
MicroserviceHealthIndicator,
} from '@nestjs/terminus';
@Controller('health-check')
export class HealthCheckController {
constructor(
private healthCheckService: HealthCheckService,
private http: HttpHealthIndicator,
private microservice: MicroserviceHealthIndicator,
) {}
@Get()
@HealthCheck()
check() {
return this.healthCheckService.check([
() => this.http.pingCheck('nestjs-docs', 'https://docs.nestjs.com'),
() =>
this.microservice.pingCheck < RmqOptions > ('rabbitmq', {
transport: Transport.RMQ,
options: {
urls: [process.env.AMQP_URL],
queue: 'user_queue',
queueOptions: {
durable: false,
},
},
}),
]);
}
}
When I hit endpoint to check health I face following error. ` { "status": "error", "info": {
},
"error": {
"nestjs-docs": {
"status": "down",
"message": "unexpected end of file"
},
"rabbitmq": {
"status": "down",
"message": "timeout of 1000ms exceeded"
}
},
"details": {
"nestjs-docs": {
"status": "down",
"message": "unexpected end of file"
},
"rabbitmq": {
"status": "down",
"message": "timeout of 1000ms exceeded"
}
}
} `
What is this error and how can I solve this error
I tried to check health but I face above mention error. I saw the documentation of Nestjs and Nestjs github examples but there is redis health check code but not rabbitmq code. I converted redis health check code to rabbitmq. But I failed to get result.