redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
68 lines • 2.89 kB
JavaScript
import { ERedisScriptName } from '../../common/redis/scripts.js';
import { redisKeys } from '../../common/redis/redis-keys/redis-keys.js';
import { EQueueDeliveryModel, EQueueOperationalState, EQueueProperty, EQueueType, } from '../../queue-manager/index.js';
import { ConsumerGroupHasActiveConsumersError, ConsumerGroupNotEmptyError, ConsumerGroupsNotSupportedError, QueueLockedError, QueueNotFoundError, UnexpectedScriptReplyError, } from '../../errors/index.js';
import { EventMultiplexer } from '../../event-bus/event-multiplexer.js';
export function _deleteConsumerGroup(redisClient, queueParams, groupId, cb) {
const { keyQueueConsumerGroups, keyQueuePending, keyQueuePriority, keyQueueProperties, } = redisKeys.getQueueKeys(queueParams.ns, queueParams.name, groupId);
const { keyQueueConsumerGroupConsumers } = redisKeys.getQueueConsumerGroupKeys(queueParams, groupId);
const argv = [
EQueueProperty.QUEUE_TYPE,
EQueueType.PRIORITY_QUEUE,
EQueueProperty.DELIVERY_MODEL,
EQueueDeliveryModel.PUB_SUB,
groupId,
EQueueProperty.OPERATIONAL_STATE,
EQueueOperationalState.LOCKED,
EQueueProperty.LOCK_ID,
'',
];
redisClient.runScript(ERedisScriptName.DELETE_CONSUMER_GROUP, [
keyQueueConsumerGroups,
keyQueuePending,
keyQueuePriority,
keyQueueProperties,
keyQueueConsumerGroupConsumers,
], argv, (err, reply) => {
if (err)
return cb(err);
const replyStr = String(reply);
if (replyStr === 'QUEUE_LOCKED') {
return cb(new QueueLockedError({
metadata: {
queue: queueParams,
},
}));
}
if (replyStr === 'QUEUE_NOT_FOUND') {
return cb(new QueueNotFoundError({
metadata: {
queue: queueParams,
},
}));
}
if (replyStr === 'CONSUMER_GROUPS_NOT_SUPPORTED') {
return cb(new ConsumerGroupsNotSupportedError());
}
if (replyStr === 'CONSUMER_GROUP_NOT_EMPTY') {
return cb(new ConsumerGroupNotEmptyError());
}
if (replyStr === 'CONSUMER_GROUP_HAS_ACTIVE_CONSUMERS') {
return cb(new ConsumerGroupHasActiveConsumersError({
metadata: {
queue: queueParams,
consumerGroupId: groupId,
},
}));
}
if (replyStr !== 'OK') {
return cb(new UnexpectedScriptReplyError({
message: `Unexpected reply from DELETE_CONSUMER_GROUP script: ${replyStr}`,
metadata: { reply },
}));
}
EventMultiplexer.publish('queue.consumerGroupDeleted', queueParams, groupId);
cb();
});
}
//# sourceMappingURL=_delete-consumer-group.js.map