redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
36 lines • 1.98 kB
JavaScript
import { CallbackEmptyReplyError } from 'redis-smq-common';
import { _getQueueProperties } from '../../../queue-manager/_/_get-queue-properties.js';
import { EQueueDeliveryModel, } from '../../../queue-manager/index.js';
import { ConsumerGroups } from '../../../consumer-groups/index.js';
import { ConsumerGroupsNotSupportedError } from '../../../errors/index.js';
import { _generateEphemeralConsumerGroupId } from './_generate-ephemeral-consumer-group-id.js';
import { withSharedPoolConnection } from '../../../common/redis/redis-connection-pool/with-shared-pool-connection.js';
export function _prepareConsumerGroup(queueParams, consumerId, cb, logger) {
withSharedPoolConnection((redisClient, cb) => {
_getQueueProperties(redisClient, queueParams.queueParams, (err, props) => {
if (err)
return cb(err);
if (!props)
return cb(new CallbackEmptyReplyError());
if (props.deliveryModel === EQueueDeliveryModel.PUB_SUB) {
const consumerGroups = new ConsumerGroups();
let effectiveGroupId = queueParams.groupId;
if (!effectiveGroupId) {
logger?.debug(`PUB_SUB queue without provided consumer group. Creating ephemeral group '${consumerId}'...`);
effectiveGroupId = _generateEphemeralConsumerGroupId(consumerId);
}
return consumerGroups.saveConsumerGroup(queueParams.queueParams, effectiveGroupId, (saveErr) => {
if (saveErr)
return cb(saveErr);
cb(null, effectiveGroupId);
});
}
if (queueParams.groupId) {
logger?.error('Consumer group ID not supported for point-to-point delivery model');
return cb(new ConsumerGroupsNotSupportedError());
}
cb();
});
}, cb);
}
//# sourceMappingURL=_prepare-consumer-group.js.map