UNPKG

@rxap/nest-rabbitmq

Version:

This package provides a NestJS module for integrating with RabbitMQ using exchanges. It offers a client and server implementation for message queuing and supports features like health checks and error serialization. It simplifies the process of setting up

31 lines (30 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RabbitmqHealthIndicator = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const terminus_1 = require("@nestjs/terminus"); const client_rmq_exchange_1 = require("./client-rmq-exchange"); const tokens_1 = require("./tokens"); let RabbitmqHealthIndicator = class RabbitmqHealthIndicator extends terminus_1.HealthIndicator { async isHealthy() { // call the connect method before checking the connection. // only on an send or emit method called a connection will be created // So it is necessary to call the connect method before checking the connection // for the case when the connection is not established yet. await this.client.connect(); const isConnected = this.client.isConnected(); if (isConnected) { return this.getStatus('rabbitmq', true); } throw new terminus_1.HealthCheckError('Connection to RabbitMQ is not established!', this.getStatus('rabbitmq', false)); } }; exports.RabbitmqHealthIndicator = RabbitmqHealthIndicator; tslib_1.__decorate([ (0, common_1.Inject)(tokens_1.RABBITMQ_EXCHANGE), tslib_1.__metadata("design:type", client_rmq_exchange_1.ClientRMQExchange) ], RabbitmqHealthIndicator.prototype, "client", void 0); exports.RabbitmqHealthIndicator = RabbitmqHealthIndicator = tslib_1.__decorate([ (0, common_1.Injectable)() ], RabbitmqHealthIndicator);