UNPKG

@nestjstools/messaging-rabbitmq-extension

Version:

Extension to handle messages and dispatch them over AMQP protocol

58 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmqpMessageBuilder = void 0; class AmqpMessageBuilder { constructor(exchangeName, routingKey, headers, message) { this.exchangeName = exchangeName; this.routingKey = routingKey; this.headers = headers; this.message = message; } static create() { return new AmqpMessageBuilder(); } withExchangeName(exchangeName) { this.exchangeName = exchangeName; return this; } withRoutingKey(routingKey) { this.routingKey = routingKey; return this; } withHeaders(headers) { this.headers = headers; return this; } addHeader(key, value) { if (!this.headers) { this.headers = {}; } this.headers[key] = value; return this; } withMessage(message) { this.message = message; return this; } buildMessage() { if (!this.exchangeName) { throw new Error('Exchange name must be defined'); } if (!this.routingKey) { throw new Error('Routing key must be defined'); } if (!this.message) { throw new Error('Message must be defined'); } return { message: this.message, envelope: { exchange: this.exchangeName, routingKey: this.routingKey, headers: this.headers ?? {}, }, }; } } exports.AmqpMessageBuilder = AmqpMessageBuilder; //# sourceMappingURL=amqp-message.builder.js.map