@ecom-micro/common 2.0.39 → 2.0.41
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.
|
@@ -9,7 +9,7 @@ export declare abstract class BaseListener<T extends Event> {
|
|
|
9
9
|
protected channel: Channel;
|
|
10
10
|
abstract exchangeName: T['exchangeName'];
|
|
11
11
|
abstract routingKey: RoutingKeyTypes;
|
|
12
|
-
abstract onMessage(data: T['data'], msg: ConsumeMessage): void;
|
|
12
|
+
abstract onMessage(data: T['data'], channel: Channel, msg: ConsumeMessage): void;
|
|
13
13
|
constructor(channel: Channel);
|
|
14
14
|
listen(): Promise<void>;
|
|
15
15
|
}
|
|
@@ -16,14 +16,18 @@ class BaseListener {
|
|
|
16
16
|
}
|
|
17
17
|
listen() {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
yield this.channel.assertExchange(this.exchangeName, 'direct'
|
|
20
|
-
|
|
19
|
+
yield this.channel.assertExchange(this.exchangeName, 'direct', {
|
|
20
|
+
durable: true,
|
|
21
|
+
});
|
|
22
|
+
const consumeQueue = yield this.channel.assertQueue(this.routingKey, {
|
|
23
|
+
durable: true,
|
|
24
|
+
});
|
|
21
25
|
yield this.channel.bindQueue(consumeQueue.queue, this.exchangeName, this.routingKey);
|
|
22
26
|
this.channel.consume(consumeQueue.queue, (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
23
27
|
console.log(`Message received: ${this.exchangeName} / ${this.routingKey}`);
|
|
24
28
|
if (msg) {
|
|
25
29
|
const parsedData = JSON.parse(msg.content.toString());
|
|
26
|
-
this.onMessage(parsedData, msg);
|
|
30
|
+
this.onMessage(parsedData, this.channel, msg);
|
|
27
31
|
}
|
|
28
32
|
}));
|
|
29
33
|
});
|