UNPKG

@xnestjs/rabbitmq

Version:

NestJS extension library for RabbitMQ

36 lines (35 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRabbitmqConfig = getRabbitmqConfig; const tslib_1 = require("tslib"); const node_process_1 = tslib_1.__importDefault(require("node:process")); const objects_1 = require("@jsopen/objects"); const putil_varhelpers_1 = require("putil-varhelpers"); function getRabbitmqConfig(init, prefix = 'RMQ_') { const env = node_process_1.default.env; const options = {}; if (Array.isArray(init)) options.hosts = init; else if (typeof init === 'object') { (0, objects_1.merge)(options, init, { deep: true }); } else options.hosts = (init || env[prefix + 'HOSTS'] || 'localhost:5672').split(/\s*,\s*/); options.vhost = options.vhost ?? env[prefix + 'VHOST']; options.username = options.username ?? env[prefix + 'USERNAME']; options.password = options.password ?? env[prefix + 'PASSWORD']; options.acquireTimeout = options.acquireTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'ACQUIRE_TIMEOUT']); options.connectionTimeout = options.connectionTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'CONNECTION_TIMEOUT']); options.frameMax = options.frameMax ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'FRAME_MAX']); options.heartbeat = options.heartbeat ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_INTERVAL']); options.maxChannels = options.maxChannels ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CHANNELS']); options.retryHigh = options.retryHigh ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'RETRY_HIGH']); options.retryLow = options.retryLow ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'NO_DELAY']); options.lazyConnect = options.lazyConnect ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LAZY_CONNECT']); return (0, objects_1.omitNullish)(options); }