UNPKG

redis-smq

Version:

A simple high-performance Redis message queue for Node.js.

37 lines 1.67 kB
import { async, CallbackEmptyReplyError, } from 'redis-smq-common'; import { redisKeys } from '../../../common/redis-keys/redis-keys.js'; import { _getQueueProperties } from '../../queue/_/_get-queue-properties.js'; import { EQueueDeliveryModel } from '../../queue/index.js'; import { ConsumerGroupsConsumerGroupsNotSupportedError, ConsumerGroupsInvalidGroupIdError, } from '../errors/index.js'; export function _saveConsumerGroup(redisClient, eventBus, queue, groupId, cb) { const gid = redisKeys.validateRedisKey(groupId); if (gid instanceof Error) cb(new ConsumerGroupsInvalidGroupIdError()); else { async.waterfall([ (cb) => _getQueueProperties(redisClient, queue, (err, properties) => { if (err) cb(err); else if (!properties) cb(new CallbackEmptyReplyError()); else if (properties.deliveryModel !== EQueueDeliveryModel.PUB_SUB) cb(new ConsumerGroupsConsumerGroupsNotSupportedError()); else cb(); }), (cb) => { const { keyQueueConsumerGroups } = redisKeys.getQueueKeys(queue, gid); redisClient.sadd(keyQueueConsumerGroups, gid, (err, reply) => { if (err) cb(err); else { if (reply) eventBus.emit('queue.consumerGroupCreated', queue, groupId); cb(null, reply); } }); }, ], cb); } } //# sourceMappingURL=_save-consumer-group.js.map