redis-smq
Version:
A simple high-performance Redis message queue for Node.js.
51 lines • 1.64 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Exchange = void 0;
const uuid_1 = require("uuid");
const destination_queue_required_error_1 = require("./errors/destination-queue-required.error");
class Exchange {
constructor(bindingParams, type) {
this.destinationQueue = null;
this.bindingParams = this.validateBindingParams(bindingParams);
this.type = type;
this.exchangeTag = this.generateExchangeTag();
}
generateExchangeTag() {
return `${this.constructor.name
.replace(/([a-z])([A-Z])/, '$1-$2')
.toLowerCase()}-${(0, uuid_1.v4)()}`;
}
setDestinationQueue(queue) {
this.destinationQueue = queue;
}
getBindingParams() {
return this.bindingParams;
}
getDestinationQueue() {
return this.destinationQueue;
}
getRequiredDestinationQueue() {
if (!this.destinationQueue) {
throw new destination_queue_required_error_1.DestinationQueueRequiredError();
}
return this.destinationQueue;
}
toJSON() {
return {
exchangeTag: this.exchangeTag,
destinationQueue: this.destinationQueue,
bindingParams: this.bindingParams,
type: this.type,
};
}
fromJSON(JSON) {
if (JSON.destinationQueue)
this.setDestinationQueue(JSON.destinationQueue);
if (JSON.exchangeTag)
this.exchangeTag = JSON.exchangeTag;
if (JSON.type)
this.type = JSON.type;
}
}
exports.Exchange = Exchange;
//# sourceMappingURL=exchange.js.map
;