@nestjstools/messaging-rabbitmq-extension
Version:
Extension to handle messages and dispatch them over AMQP protocol
58 lines • 1.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AmqpMessageBuilder = void 0;
class AmqpMessageBuilder {
constructor(exchangeName = undefined, routingKey = undefined, headers = undefined, message = undefined) {
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 === undefined) {
throw new Error('Exchange name must be defined');
}
if (this.routingKey === undefined) {
throw new Error('RoutingKey name must be defined');
}
if (this.message === undefined) {
throw new Error('Message name 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