@nestjstools/messaging-rabbitmq-extension
Version:
Extension to handle messages and dispatch them over AMQP protocol
55 lines • 2.43 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RabbitmqMigrator = void 0;
const common_1 = require("@nestjs/common");
const messaging_1 = require("@nestjstools/messaging");
let RabbitmqMigrator = class RabbitmqMigrator {
async run(channel) {
if (false === channel.config.autoCreate) {
return;
}
await channel.connection.exchangeDeclare({
durable: true,
exchange: channel.config.exchangeName,
type: channel.config.exchangeType,
});
await channel.connection.queueDeclare({
durable: true,
queue: channel.config.queue,
});
if (channel.config.deadLetterQueueFeature === true) {
await channel.connection.exchangeDeclare({
durable: true,
exchange: 'dead_letter.exchange',
type: messaging_1.ExchangeType.DIRECT,
});
await channel.connection.queueDeclare({
durable: true,
queue: `${channel.config.queue}_dead_letter`,
});
await channel.connection.queueBind({
queue: `${channel.config.queue}_dead_letter`,
exchange: 'dead_letter.exchange',
routingKey: `${channel.config.queue}_dead_letter`,
});
}
for (const bindingKey of channel.config.bindingKeys) {
await channel.connection.queueBind({
queue: channel.config.queue,
exchange: channel.config.exchangeName,
routingKey: bindingKey,
});
}
}
};
exports.RabbitmqMigrator = RabbitmqMigrator;
exports.RabbitmqMigrator = RabbitmqMigrator = __decorate([
(0, common_1.Injectable)()
], RabbitmqMigrator);
//# sourceMappingURL=rabbitmq.migrator.js.map