You have applied the Microservice architecture pattern. Sometimes a service instance can be incapable of handling requests yet still be running. For example, it might have run out of database connections. When this occurs, the monitoring system should generate an alert.
In a microservice MYSQL, Redis, and RabbitMq is used, then how to make sure MYSQL, Redis, and RabbitMQ are alive.
Create an API for the health check of the server. In which we are checking the connection of MYSQL, Redis, and RabbitMQ.
MySQL Health check code in NodeJs with TypeScript.
mySQLHealthStatus() Method check the health of MySQL by run the "SELECT 1" query.
if OUTPUT is 1(ONE) return true
else return false.
Redis Health check code in NodeJs with TypeScript.
redisHealthStatus() Method check the health of Redis by run Redis "PING" CMD.
if OUTPUT is "PONG" return true else return false.
RabbitMQ Health check code in NodeJs with TypeScript
rabbitMQHealthStatus() Method check the health of RabbitMQ by making a connection with RabbitMQ server because there are many ways to check the health of RabbitMQ but this is simplest way to check the health of RabbitMQ.
if there is no error in connection making return true else return false.