redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
45 lines • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._unsubscribeConsumer = _unsubscribeConsumer;
const scripts_js_1 = require("../../../common/redis/scripts.js");
const index_js_1 = require("../../../errors/index.js");
const redis_keys_js_1 = require("../../../common/redis/redis-keys/redis-keys.js");
const with_shared_pool_connection_js_1 = require("../../../common/redis/redis-connection-pool/with-shared-pool-connection.js");
function _unsubscribeConsumer(consumerId, queueParams, cb) {
(0, with_shared_pool_connection_js_1.withSharedPoolConnection)((redisClient, cb) => {
const { queueParams: queue, groupId } = queueParams;
const { keyQueueProcessingQueues, keyQueueConsumers, keyQueueProperties } = redis_keys_js_1.redisKeys.getQueueKeys(queue.ns, queue.name, groupId);
const { keyQueueProcessing } = redis_keys_js_1.redisKeys.getQueueConsumerKeys(queue, consumerId);
const { keyConsumerQueues } = redis_keys_js_1.redisKeys.getConsumerKeys(consumerId);
const keys = [
keyQueueProperties,
keyQueueConsumers,
keyConsumerQueues,
keyQueueProcessingQueues,
keyQueueProcessing,
];
if (groupId) {
const { keyQueueConsumerGroupConsumers } = redis_keys_js_1.redisKeys.getQueueConsumerGroupKeys(queue, groupId);
keys.push(keyQueueConsumerGroupConsumers);
}
const args = [consumerId, JSON.stringify(queue)];
redisClient.runScript(scripts_js_1.ERedisScriptName.UNSUBSCRIBE_CONSUMER, keys, args, (err, reply) => {
if (err)
return cb(err);
if (reply === 'QUEUE_NOT_FOUND')
return cb(new index_js_1.QueueNotFoundError({
metadata: {
queue: queue,
},
}));
if (reply === 'PROCESSING_QUEUE_NOT_EMPTY')
return cb(new index_js_1.ProcessingQueueNotEmptyError({
metadata: { consumerId, queue, groupId },
}));
if (reply === 'OK')
return cb();
cb(new index_js_1.UnexpectedScriptReplyError({ metadata: { reply } }));
});
}, cb);
}
//# sourceMappingURL=_unsubscribe-consumer.js.map