@raymanselltickets/common 1.0.16 → 1.0.18
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.
|
@@ -6,8 +6,7 @@ interface Event {
|
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class Listener<T extends Event> {
|
|
8
8
|
abstract subject: T['subject'];
|
|
9
|
-
abstract
|
|
10
|
-
abstract onMessage(data: T['data'], msg: JsMsg): void;
|
|
9
|
+
abstract onMessage(data: T['data'], msg: JsMsg): Promise<void>;
|
|
11
10
|
private jsManager;
|
|
12
11
|
private jsClient;
|
|
13
12
|
protected ackWait: number;
|
|
@@ -11,6 +11,7 @@ export class Listener {
|
|
|
11
11
|
async listen() {
|
|
12
12
|
// find the stream that stores a specific subject
|
|
13
13
|
const stream = await this.jsManager.streams.find(this.subject);
|
|
14
|
+
// aparently restarting a pod doesn't cause consumers to be re-added?
|
|
14
15
|
const consumerInfo = await this.jsManager.consumers.add(stream, {
|
|
15
16
|
durable_name: `durable-consumer:${this.subject}`,
|
|
16
17
|
filter_subject: this.subject,
|
|
@@ -21,14 +22,14 @@ export class Listener {
|
|
|
21
22
|
});
|
|
22
23
|
const consumer = await this.jsClient.consumers.get(stream, consumerInfo.name);
|
|
23
24
|
while (true) {
|
|
24
|
-
console.log(`[${
|
|
25
|
-
const messages = await consumer.consume();
|
|
25
|
+
console.log(`[${consumerInfo.name}] Waiting for ${this.subject} messages...`);
|
|
26
|
+
const messages = await consumer.consume({ max_messages: 1 });
|
|
26
27
|
try {
|
|
27
28
|
for await (const msg of messages) {
|
|
28
|
-
console.log(`Message received: ${this.subject} / ${
|
|
29
|
+
console.log(`Message received: ${this.subject} / ${stream}`);
|
|
29
30
|
console.log(msg.seq, msg.string());
|
|
30
31
|
const parsedData = msg.json();
|
|
31
|
-
this.onMessage(parsedData, msg); // msg is ack'd in this handler
|
|
32
|
+
await this.onMessage(parsedData, msg); // msg is ack'd in this handler
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
catch (err) {
|