redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
56 lines • 3.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._validateQueueBinding = _validateQueueBinding;
const redis_smq_common_1 = require("redis-smq-common");
const index_js_1 = require("../../errors/index.js");
const _get_queue_properties_js_1 = require("../../queue-manager/_/_get-queue-properties.js");
const index_js_2 = require("../../queue-manager/index.js");
const index_js_3 = require("../types/index.js");
const _get_exchange_properties_js_1 = require("./_get-exchange-properties.js");
function _validateQueueBinding(client, exchangeParams, queueParams, cb) {
redis_smq_common_1.async.series([
(cb1) => (0, _get_queue_properties_js_1._getQueueProperties)(client, queueParams, cb1),
(cb1) => {
(0, _get_exchange_properties_js_1._getExchangeProperties)(client, exchangeParams, (err, reply) => {
if (err instanceof index_js_1.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 index_js_1.ExchangeTypeMismatchError({
metadata: {
expected: exchangeParams.type,
actual: exchangeProperties.type,
},
}));
}
const queueType = queueProperties.queueType;
if ((exchangeProperties.queuePolicy === index_js_3.EExchangeQueuePolicy.STANDARD &&
![index_js_2.EQueueType.FIFO_QUEUE, index_js_2.EQueueType.LIFO_QUEUE].includes(queueType)) ||
(exchangeProperties.queuePolicy === index_js_3.EExchangeQueuePolicy.PRIORITY &&
index_js_2.EQueueType.PRIORITY_QUEUE !== queueType)) {
const expected = exchangeProperties.queuePolicy === index_js_3.EExchangeQueuePolicy.STANDARD
? `${index_js_2.EQueueType[index_js_2.EQueueType.FIFO_QUEUE]} or ${index_js_2.EQueueType[index_js_2.EQueueType.LIFO_QUEUE]}`
: `${index_js_2.EQueueType[index_js_2.EQueueType.PRIORITY_QUEUE]}`;
const actual = index_js_2.EQueueType[queueType];
return cb(new index_js_1.ExchangeQueuePolicyMismatchError({
message: `Queue policy mismatch for ${index_js_3.EExchangeType[exchangeProperties.type]} exchange: expected ${expected} queue, but got ${index_js_2.EQueueType[queueType]}.`,
metadata: {
exchangeType: exchangeProperties.type,
queuePolicy: exchangeProperties.queuePolicy,
expected: expected,
actual: actual,
},
}));
}
}
}
cb(err, result);
});
}
//# sourceMappingURL=_validate-queue-binding.js.map