n8n
Version:
n8n Workflow Automation Tool
72 lines • 3.32 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.RedisServicePubSubSubscriber = void 0;
const typedi_1 = require("typedi");
const RedisServiceHelper_1 = require("./RedisServiceHelper");
const RedisServiceBaseClasses_1 = require("./RedisServiceBaseClasses");
let RedisServicePubSubSubscriber = class RedisServicePubSubSubscriber extends RedisServiceBaseClasses_1.RedisServiceBaseReceiver {
async init() {
var _a;
await super.init('subscriber');
(_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.on('message', (channel, message) => {
this.messageHandlers.forEach((handler) => handler(channel, message));
});
}
async subscribe(channel) {
var _a;
if (!this.redisClient) {
await this.init();
}
await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.subscribe(channel, (error, _count) => {
if (error) {
this.logger.error(`Error subscribing to channel ${channel}`);
}
else {
this.logger.debug(`Subscribed Redis PubSub client to channel: ${channel}`);
}
}));
}
async unsubscribe(channel) {
var _a;
if (!this.redisClient) {
return;
}
await ((_a = this.redisClient) === null || _a === void 0 ? void 0 : _a.unsubscribe(channel, (error, _count) => {
if (error) {
this.logger.error(`Error unsubscribing from channel ${channel}`);
}
else {
this.logger.debug(`Unsubscribed Redis PubSub client from channel: ${channel}`);
}
}));
}
async subscribeToEventLog() {
await this.subscribe(RedisServiceHelper_1.EVENT_BUS_REDIS_CHANNEL);
}
async subscribeToCommandChannel() {
await this.subscribe(RedisServiceHelper_1.COMMAND_REDIS_CHANNEL);
}
async subscribeToWorkerResponseChannel() {
await this.subscribe(RedisServiceHelper_1.WORKER_RESPONSE_REDIS_CHANNEL);
}
async unSubscribeFromEventLog() {
await this.unsubscribe(RedisServiceHelper_1.EVENT_BUS_REDIS_CHANNEL);
}
async unSubscribeFromCommandChannel() {
await this.unsubscribe(RedisServiceHelper_1.COMMAND_REDIS_CHANNEL);
}
async unSubscribeFromWorkerResponseChannel() {
await this.unsubscribe(RedisServiceHelper_1.WORKER_RESPONSE_REDIS_CHANNEL);
}
};
exports.RedisServicePubSubSubscriber = RedisServicePubSubSubscriber;
exports.RedisServicePubSubSubscriber = RedisServicePubSubSubscriber = __decorate([
(0, typedi_1.Service)()
], RedisServicePubSubSubscriber);
//# sourceMappingURL=RedisServicePubSubSubscriber.js.map
;