@xtreamr/ds_rabbitmq
Advanced tools
Comparing version 2.0.14 to 2.0.15
{ | ||
"name": "@xtreamr/ds_rabbitmq", | ||
"version": "2.0.14", | ||
"version": "2.0.15", | ||
"description": "RabbitMQ queues", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,11 +7,13 @@ 'use strict'; | ||
const logger = require("@xtreamr/logger")(module) | ||
let connection | ||
function connectRabbitMQ(config, callback) { | ||
function connectRabbitMQ(config) { | ||
return amqplib | ||
.connect(config.messageQueue) | ||
.then(async (conn) => { | ||
.then((conn) => { | ||
conn.on("close", function () { | ||
logger.error("Reconnecting AMQP Server"); | ||
connection = null | ||
return setTimeout(function () { | ||
connectRabbitMQ(config, callback); | ||
connectRabbitMQ(config); | ||
}, config.rabbitmq.attemptTime); | ||
@@ -23,10 +25,34 @@ }); | ||
} | ||
connection = null | ||
return setTimeout(function () { | ||
connectRabbitMQ(config, callback); | ||
connectRabbitMQ(config); | ||
}, config.rabbitmq.attemptTime); | ||
}); | ||
logger.info( | ||
`Connected to AMQP server as ${config.messageQueue.username}@${config.messageQueue.hostname}${config.messageQueue.vhost}`, | ||
); | ||
if (conn && !connection) { | ||
logger.info( | ||
`Connected to AMQP server as ${config.messageQueue.username}@${config.messageQueue.hostname}${config.messageQueue.vhost}`, | ||
); | ||
if (config.rabbitmq.queues && config.rabbitmq.queues.sendAndForget) { | ||
config.rabbitmq.queues.sendAndForget.forEach((queue) => { | ||
require(name).sendAndForget(queue, config); | ||
}); | ||
} | ||
if (config.rabbitmq.queues && config.rabbitmq.queues.rpc) { | ||
config.rabbitmq.queues.rpc.forEach((queue) => { | ||
require(name).rpc(queue, config); | ||
}); | ||
} | ||
if (fs.existsSync(process.cwd() + "/frontend")) { | ||
require(process.cwd() + "/frontend").start(); | ||
logger.info('Modules loaded') | ||
} else if(config.rabbitmq && config.rabbitmq.consumerPath) { | ||
require(config.rabbitmq.consumerPath).start() | ||
logger.info('Modules loaded') | ||
} | ||
} | ||
connection = conn | ||
return conn | ||
@@ -36,4 +62,5 @@ }) | ||
logger.error(`AMQP ${err.message} ${err.stack}`); | ||
connection = null | ||
return setTimeout(function () { | ||
connectRabbitMQ(config, callback); | ||
connectRabbitMQ(config); | ||
}, config.rabbitmq.attemptTime); | ||
@@ -43,28 +70,5 @@ }); | ||
function connectPromise(config, callback) { | ||
return connectRabbitMQ(config, callback) | ||
.then(() => { | ||
if (config.rabbitmq.queues && config.rabbitmq.queues.sendAndForget) { | ||
config.rabbitmq.queues.sendAndForget.forEach((queue) => { | ||
require(name).sendAndForget(queue, config); | ||
}); | ||
} | ||
if (config.rabbitmq.queues && config.rabbitmq.queues.rpc) { | ||
config.rabbitmq.queues.rpc.forEach((queue) => { | ||
require(name).rpc(queue, config); | ||
}); | ||
} | ||
if (fs.existsSync(process.cwd() + "/frontend")) { | ||
require(process.cwd() + "/frontend").start(); | ||
} else if(config.rabbitmq && config.rabbitmq.restart) { | ||
require(config.rabbitmq.restart).start() | ||
logger.info('Modules loaded') | ||
} | ||
if (callback !== undefined) { | ||
callback(); | ||
} else { | ||
return Promise.resolve(); | ||
} | ||
}) | ||
function connectPromise(config) { | ||
return connectRabbitMQ(config) | ||
.then(() => Promise.resolve()) | ||
} | ||
@@ -71,0 +75,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
13806
402