@nomikos/module-comm 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/amqpServer.js +33 -30
- package/src/services/AmqpReceiver.js +3 -2
package/package.json
CHANGED
package/src/lib/amqpServer.js
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
const { env } = require(
|
|
2
|
-
const amqp = require(
|
|
3
|
-
const amqpHost = env[
|
|
1
|
+
const { env } = require("./env");
|
|
2
|
+
const amqp = require("amqp-connection-manager");
|
|
3
|
+
const amqpHost = env["amqp-host"];
|
|
4
4
|
|
|
5
5
|
// No se puede exportar en commonJs (es null)
|
|
6
|
-
let amqpConn = null
|
|
6
|
+
let amqpConn = null;
|
|
7
7
|
|
|
8
8
|
function amqpClientConnect(loggerRoot) {
|
|
9
9
|
if (!loggerRoot) {
|
|
10
|
-
loggerRoot = console
|
|
10
|
+
loggerRoot = console;
|
|
11
11
|
// console.warn escribe a pm2 logs
|
|
12
|
-
loggerRoot.debug = console.warn
|
|
13
|
-
loggerRoot.fatal = console.warn
|
|
12
|
+
loggerRoot.debug = console.warn;
|
|
13
|
+
loggerRoot.fatal = console.warn;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
17
|
if (amqpConn !== null) {
|
|
18
18
|
if (amqpConn.isConnected()) {
|
|
19
|
-
loggerRoot.debug(
|
|
20
|
-
return resolve(amqpConn)
|
|
19
|
+
loggerRoot.debug("Devolviendo conneccion amqp ya iniciada");
|
|
20
|
+
return resolve(amqpConn);
|
|
21
21
|
}
|
|
22
22
|
} else {
|
|
23
|
-
loggerRoot.debug(
|
|
23
|
+
loggerRoot.debug("Iniciando nueva conneccion amqp");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Devuelve singleton. Se conecta ahora.
|
|
27
|
-
amqpConn = amqp.connect(amqpHost)
|
|
27
|
+
amqpConn = amqp.connect(amqpHost);
|
|
28
28
|
|
|
29
29
|
// Emitted whenever we successfully connect to a broker.
|
|
30
|
-
amqpConn.on(
|
|
31
|
-
loggerRoot.debug(
|
|
32
|
-
resolve(amqpConn)
|
|
33
|
-
})
|
|
30
|
+
amqpConn.on("connect", function (a, b) {
|
|
31
|
+
loggerRoot.debug("CLIENTE AMQP CONECTADO");
|
|
32
|
+
resolve(amqpConn);
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
amqpConn.on(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
amqpConn.on("error", (err) => {
|
|
36
|
+
loggerRoot.debug("********* Error en la conexión:", err.message);
|
|
37
|
+
console.log("********* Error en la conexión:", err.message);
|
|
38
|
+
console.error("********* Error en la conexión:", err.message);
|
|
39
|
+
});
|
|
39
40
|
|
|
40
|
-
amqpConn.on(
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
amqpConn.on("close", () => {
|
|
42
|
+
loggerRoot.debug("********* La conexión se ha cerrado.");
|
|
43
|
+
console.log("********* La conexión se ha cerrado.");
|
|
44
|
+
});
|
|
43
45
|
|
|
44
46
|
// Emitted whenever we disconnect from a broker.
|
|
45
|
-
amqpConn.on(
|
|
46
|
-
const error = params.err
|
|
47
|
-
|
|
47
|
+
amqpConn.on("disconnect", function (params) {
|
|
48
|
+
const error = params.err;
|
|
49
|
+
console.error(`error`, error);
|
|
50
|
+
if (error.includes && error.includes("PRECONDITION_FAILED")) {
|
|
48
51
|
/**
|
|
49
52
|
* This error results in the channel that was used for the declaration being
|
|
50
53
|
* forcibly closed by RabbitMQ. If the program subsequently tries to
|
|
@@ -57,11 +60,11 @@ function amqpClientConnect(loggerRoot) {
|
|
|
57
60
|
* presente instancia de app.
|
|
58
61
|
* Luego habria quer reparar cola.
|
|
59
62
|
*/
|
|
60
|
-
loggerRoot.fatal(
|
|
63
|
+
loggerRoot.fatal("Sacar cola de lista de colas !", error);
|
|
61
64
|
}
|
|
62
|
-
loggerRoot.fatal(
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
+
loggerRoot.fatal("CLIENTE AMQP DESCONECTADO, error.stack:", error.stack);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
module.exports = amqpClientConnect
|
|
70
|
+
module.exports = amqpClientConnect;
|
|
@@ -27,10 +27,11 @@ module.exports = {
|
|
|
27
27
|
Object.keys(colas).map(async (queueName) => {
|
|
28
28
|
const cola = colas[queueName];
|
|
29
29
|
const options = cola.options;
|
|
30
|
+
const dlOptions = cola.dlOptions ?? { durable: true };
|
|
30
31
|
const prefetch = cola.prefetch || 1;
|
|
32
|
+
// console.log(`dlOptions`, dlOptions)
|
|
31
33
|
|
|
32
34
|
try {
|
|
33
|
-
// Uso correcto de promesas sin envolver en una nueva promesa innecesariamente
|
|
34
35
|
await ch.assertQueue(queueName, options);
|
|
35
36
|
if (
|
|
36
37
|
options.arguments &&
|
|
@@ -44,7 +45,7 @@ module.exports = {
|
|
|
44
45
|
await ch.assertExchange(exc, "direct", { durable: true });
|
|
45
46
|
|
|
46
47
|
loggerRoot.debug(`Creando dead letter: ${queueName}.dl`);
|
|
47
|
-
await ch.assertQueue(`${queueName}.dl`,
|
|
48
|
+
await ch.assertQueue(`${queueName}.dl`, dlOptions);
|
|
48
49
|
|
|
49
50
|
loggerRoot.debug(`Binding dead letter: ${queueName}.dl`);
|
|
50
51
|
await ch.bindQueue(`${queueName}.dl`, exc, rk);
|