UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

53 lines 2.82 kB
import { async } from 'redis-smq-common'; import { ExchangeNotFoundError, ExchangeQueuePolicyMismatchError, ExchangeTypeMismatchError, } from '../../errors/index.js'; import { _getQueueProperties } from '../../queue-manager/_/_get-queue-properties.js'; import { EQueueType, } from '../../queue-manager/index.js'; import { EExchangeQueuePolicy, EExchangeType, } from '../types/index.js'; import { _getExchangeProperties } from './_get-exchange-properties.js'; export function _validateQueueBinding(client, exchangeParams, queueParams, cb) { async.series([ (cb1) => _getQueueProperties(client, queueParams, cb1), (cb1) => { _getExchangeProperties(client, exchangeParams, (err, reply) => { if (err instanceof ExchangeNotFoundError) return cb1(null, null); cb1(err, reply); }); }, ], (err, result) => { if (result) { const [queueProperties, exchangeProperties] = result; if (exchangeProperties) { if (exchangeProperties.type !== exchangeParams.type) { return cb(new ExchangeTypeMismatchError({ metadata: { expected: exchangeParams.type, actual: exchangeProperties.type, }, })); } const queueType = queueProperties.queueType; if ((exchangeProperties.queuePolicy === EExchangeQueuePolicy.STANDARD && ![EQueueType.FIFO_QUEUE, EQueueType.LIFO_QUEUE].includes(queueType)) || (exchangeProperties.queuePolicy === EExchangeQueuePolicy.PRIORITY && EQueueType.PRIORITY_QUEUE !== queueType)) { const expected = exchangeProperties.queuePolicy === EExchangeQueuePolicy.STANDARD ? `${EQueueType[EQueueType.FIFO_QUEUE]} or ${EQueueType[EQueueType.LIFO_QUEUE]}` : `${EQueueType[EQueueType.PRIORITY_QUEUE]}`; const actual = EQueueType[queueType]; return cb(new ExchangeQueuePolicyMismatchError({ message: `Queue policy mismatch for ${EExchangeType[exchangeProperties.type]} exchange: expected ${expected} queue, but got ${EQueueType[queueType]}.`, metadata: { exchangeType: exchangeProperties.type, queuePolicy: exchangeProperties.queuePolicy, expected: expected, actual: actual, }, })); } } } cb(err, result); }); } //# sourceMappingURL=_validate-queue-binding.js.map