redis-smq
Version:
A simple high-performance Redis message queue for Node.js.
81 lines • 3.14 kB
JavaScript
import { async, CallbackEmptyReplyError, logger, } from 'redis-smq-common';
import { RedisClient } from '../../common/redis-client/redis-client.js';
import { Configuration } from '../../config/index.js';
import { EventBus } from '../event-bus/index.js';
import { _parseQueueParams } from '../queue/_/_parse-queue-params.js';
import { _deleteConsumerGroup } from './_/_delete-consumer-group.js';
import { _getConsumerGroups } from './_/_get-consumer-groups.js';
import { _saveConsumerGroup } from './_/_save-consumer-group.js';
export class ConsumerGroups {
redisClient;
eventBus;
logger;
constructor() {
this.logger = logger.getLogger(Configuration.getSetConfig().logger, `consumer-groups`);
this.eventBus = new EventBus();
this.eventBus.on('error', (err) => this.logger.error(err));
this.redisClient = new RedisClient();
this.redisClient.on('error', (err) => this.logger.error(err));
}
saveConsumerGroup(queue, groupId, cb) {
const queueParams = _parseQueueParams(queue);
if (queueParams instanceof Error)
cb(queueParams);
else {
this.redisClient.getSetInstance((err, client) => {
if (err)
cb(err);
else if (!client)
cb(new CallbackEmptyReplyError());
else {
this.eventBus.getSetInstance((err, eventBus) => {
if (eventBus)
_saveConsumerGroup(client, eventBus, queueParams, groupId, cb);
else
cb(err);
});
}
});
}
}
deleteConsumerGroup(queue, groupId, cb) {
const queueParams = _parseQueueParams(queue);
if (queueParams instanceof Error)
cb(queueParams);
else {
async.waterfall([
(cb) => this.redisClient.getSetInstance(cb),
(redisClient, cb) => {
this.eventBus.getSetInstance((err, eventBus) => {
if (eventBus)
cb(null, { redisClient, eventBus });
else
cb(err);
});
},
(args, cb) => {
_deleteConsumerGroup(args.redisClient, args.eventBus, queueParams, groupId, cb);
},
], cb);
}
}
getConsumerGroups(queue, cb) {
const queueParams = _parseQueueParams(queue);
if (queueParams instanceof Error)
cb(queueParams);
else {
this.redisClient.getSetInstance((err, client) => {
if (err)
cb(err);
else if (!client)
cb(new CallbackEmptyReplyError());
else
_getConsumerGroups(client, queueParams, cb);
});
}
}
shutdown = (cb) => {
async.waterfall([this.redisClient.shutdown, this.eventBus.shutdown], cb);
};
}
//# sourceMappingURL=consumer-groups.js.map