@xnestjs/rabbitmq
Version:
NestJS extension library for RabbitMQ
30 lines (29 loc) • 1.49 kB
JavaScript
;
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(moduleOptions, prefix = 'RMQ_') {
const options = (0, objects_1.clone)(moduleOptions);
const env = node_process_1.default.env;
options.urls =
options.urls ||
(env[prefix + 'URLS'] ?? 'amqp://localhost:5672').split(/\s*,\s*/);
options.prefetchCount =
options.prefetchCount ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PREFETCH_COUNT']);
options.maxConnectionAttempts =
options.maxConnectionAttempts ??
(0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTION_ATTEMPTS']);
options.socketOptions = options.socketOptions ?? {};
options.socketOptions.reconnectTimeInSeconds =
options.socketOptions.reconnectTimeInSeconds ??
(0, putil_varhelpers_1.toInt)(env[prefix + 'RECONNECT_TIME']);
options.socketOptions.heartbeatIntervalInSeconds =
options.socketOptions.heartbeatIntervalInSeconds ??
(0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_INTERVAL']);
options.lazyConnect =
options.lazyConnect ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LAZY_CONNECT'] ?? 'false');
return options;
}