@golemio/core 1.2.8-dev.529201008 → 1.2.9-dev.530956955
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/dist/input-gateway/controllers/BaseController.js +9 -2
- package/dist/input-gateway/controllers/BaseController.js.map +1 -1
- package/dist/integration-engine/queueprocessors/QueueProcessor.d.ts +6 -0
- package/dist/integration-engine/queueprocessors/QueueProcessor.js +22 -2
- package/dist/integration-engine/queueprocessors/QueueProcessor.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,12 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.BaseController = void 0;
|
|
13
|
-
const
|
|
16
|
+
const AlternateExchangeCreator_1 = __importDefault(require("../../helpers/data-access/amqp/AlternateExchangeCreator"));
|
|
14
17
|
const config_1 = require("../config");
|
|
15
18
|
const connectors_1 = require("../connectors");
|
|
16
19
|
const sentry_transactions_1 = require("../../monitoring/sentry/sentry-transactions");
|
|
20
|
+
const errors_1 = require("@golemio/errors");
|
|
17
21
|
/**
|
|
18
22
|
* Base controller class, defines basic structure of a controller. ProcessData function, mandatory name
|
|
19
23
|
*/
|
|
@@ -25,7 +29,10 @@ class BaseController {
|
|
|
25
29
|
this.sendMessage = (key, msg, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
26
30
|
try {
|
|
27
31
|
const ch = yield connectors_1.AMQPConnector.getChannel();
|
|
28
|
-
yield ch.assertExchange(config_1.config.rabbit_exchange_name, "topic", {
|
|
32
|
+
yield ch.assertExchange(config_1.config.rabbit_exchange_name, "topic", {
|
|
33
|
+
durable: false,
|
|
34
|
+
alternateExchange: AlternateExchangeCreator_1.default.getAltExchangeName(config_1.config.rabbit_exchange_name),
|
|
35
|
+
});
|
|
29
36
|
yield ch.publish(config_1.config.rabbit_exchange_name, key, Buffer.from(msg), options);
|
|
30
37
|
}
|
|
31
38
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../../../src/input-gateway/controllers/BaseController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../../../src/input-gateway/controllers/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uHAA0F;AAC1F,sCAAoC;AACpC,8CAA+C;AAC/C,qFAAiF;AACjF,4CAA8C;AAG9C;;GAEG;AACH,MAAsB,cAAc;IAUhC,YAAY,IAAY,EAAE,SAAqB;QAM/C;;WAEG;QACK,gBAAW,GAAG,CAAO,GAAW,EAAE,GAAQ,EAAE,UAAkB,EAAE,EAAiB,EAAE;YACvF,IAAI;gBACA,MAAM,EAAE,GAAG,MAAM,0BAAa,CAAC,UAAU,EAAE,CAAC;gBAC5C,MAAM,EAAE,CAAC,cAAc,CAAC,eAAM,CAAC,oBAA8B,EAAE,OAAO,EAAE;oBACpE,OAAO,EAAE,KAAK;oBACd,iBAAiB,EAAE,kCAAwB,CAAC,kBAAkB,CAAC,eAAM,CAAC,oBAAqB,CAAC;iBAC/F,CAAC,CAAC;gBACH,MAAM,EAAE,CAAC,OAAO,CAAC,eAAM,CAAC,oBAA8B,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;aAC3F;YAAC,OAAO,GAAG,EAAE;gBACV,MAAM,IAAI,oBAAW,CAAC,yCAAyC,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aACtG;QACL,CAAC,CAAA,CAAC;QAEQ,0BAAqB,GAAG,IAAA,6CAAuB,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QArBxE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,YAAY,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,eAAM,CAAC,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9E,CAAC;CAmBJ;AAjCD,wCAiCC"}
|
|
@@ -3,11 +3,17 @@ import amqplib from "amqplib";
|
|
|
3
3
|
export declare class QueueProcessor {
|
|
4
4
|
protected channel: amqplib.Channel;
|
|
5
5
|
private definition;
|
|
6
|
+
private consumers;
|
|
7
|
+
private isGracefulShutdown;
|
|
6
8
|
constructor(channel: amqplib.Channel, definition: IQueueDefinition);
|
|
7
9
|
/**
|
|
8
10
|
* Registering all queues from definition
|
|
9
11
|
*/
|
|
10
12
|
registerQueues: () => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Cancel all registered consumers before shutting down
|
|
15
|
+
*/
|
|
16
|
+
cancelConsumers: () => Promise<void>;
|
|
11
17
|
/**
|
|
12
18
|
* Default queue processor
|
|
13
19
|
*/
|
|
@@ -33,7 +33,7 @@ class QueueProcessor {
|
|
|
33
33
|
// default processor
|
|
34
34
|
yield this.defaultProcessor(msg, q.name, () => __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
if (!q.worker || !q.workerMethod) {
|
|
36
|
-
throw new errors_1.CustomError("[AMQP] Worker and worker method must be defined.", false, this.constructor.name, 5005);
|
|
36
|
+
throw new errors_1.CustomError("[AMQP QueueProcessor] Worker and worker method must be defined.", false, this.constructor.name, 5005);
|
|
37
37
|
}
|
|
38
38
|
const w = new q.worker();
|
|
39
39
|
yield (0, sentry_transactions_1.withSentryConsumerTrace)(w[q.workerMethod].bind(w))(msg);
|
|
@@ -43,12 +43,29 @@ class QueueProcessor {
|
|
|
43
43
|
});
|
|
44
44
|
yield Promise.all(promises);
|
|
45
45
|
});
|
|
46
|
+
/**
|
|
47
|
+
* Cancel all registered consumers before shutting down
|
|
48
|
+
*/
|
|
49
|
+
this.cancelConsumers = () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
helpers_1.log.info("[AMQP QueueProcessor] Expecting a shutdown. Cancelling all consumer operations");
|
|
51
|
+
this.isGracefulShutdown = true;
|
|
52
|
+
// Cancel all consumer operations
|
|
53
|
+
for (const consumerTag of this.consumers.values()) {
|
|
54
|
+
yield this.channel.cancel(consumerTag);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
46
57
|
/**
|
|
47
58
|
* Default queue processor
|
|
48
59
|
*/
|
|
49
60
|
this.defaultProcessor = (msg, name, worker) => __awaiter(this, void 0, void 0, function* () {
|
|
50
61
|
try {
|
|
51
62
|
helpers_1.log.verbose("[>] " + this.definition.queuePrefix + "." + name + ": received some data.");
|
|
63
|
+
// Expect to requeue the message before shutting down
|
|
64
|
+
if (this.isGracefulShutdown) {
|
|
65
|
+
this.channel.nack(msg, false, true);
|
|
66
|
+
helpers_1.log.verbose("[<] " + this.definition.queuePrefix + "." + name + ": requeued");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
52
69
|
yield worker();
|
|
53
70
|
this.channel.ack(msg);
|
|
54
71
|
helpers_1.log.verbose("[<] " + this.definition.queuePrefix + "." + name + ": done");
|
|
@@ -83,10 +100,13 @@ class QueueProcessor {
|
|
|
83
100
|
yield this.channel.bindQueue(q.queue, config_1.config.RABBIT_EXCHANGE_NAME, key);
|
|
84
101
|
helpers_1.log.verbose("[*] Waiting for messages in " + name + ". {key " + key + "}");
|
|
85
102
|
// Listen and consume messages in queue
|
|
86
|
-
yield this.channel.consume(name, processor, { noAck: false });
|
|
103
|
+
const { consumerTag } = yield this.channel.consume(name, processor, { noAck: false });
|
|
104
|
+
this.consumers.add(consumerTag);
|
|
87
105
|
});
|
|
88
106
|
this.channel = channel;
|
|
89
107
|
this.definition = definition;
|
|
108
|
+
this.consumers = new Set();
|
|
109
|
+
this.isGracefulShutdown = false;
|
|
90
110
|
}
|
|
91
111
|
}
|
|
92
112
|
exports.QueueProcessor = QueueProcessor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueProcessor.js","sourceRoot":"","sources":["../../../src/integration-engine/queueprocessors/QueueProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uHAA0F;AAC1F,sCAAoC;AACpC,wCAAuF;AAEvF,qFAAiF;AACjF,4CAA8C;AAG9C,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"QueueProcessor.js","sourceRoot":"","sources":["../../../src/integration-engine/queueprocessors/QueueProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uHAA0F;AAC1F,sCAAoC;AACpC,wCAAuF;AAEvF,qFAAiF;AACjF,4CAA8C;AAG9C,MAAa,cAAc;IAMvB,YAAY,OAAwB,EAAE,UAA4B;QAOlE;;WAEG;QACI,mBAAc,GAAG,GAAwB,EAAE;YAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC9C,OAAO,IAAI,CAAC,aAAa,CACrB,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,aAAa;gBACzD,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,qBAAqB;gBACxE,CAAC,CAAC,qBAAqB,CAAC,kBAAkB;oBACtC,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,mCAAmC;oBAC7D,CAAC,CAAC,CAAO,GAAG,EAAE,EAAE;wBACV,oBAAoB;wBACpB,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,GAAS,EAAE;4BAChD,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC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