@nextage/era-lib 1.0.67 → 1.0.68
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,11 +6,26 @@ export declare abstract class Listener<T extends Event> {
|
|
|
6
6
|
abstract onMessage(data: T['data'], msg: Message): void;
|
|
7
7
|
private readonly client;
|
|
8
8
|
private subscription;
|
|
9
|
+
private messageStack;
|
|
10
|
+
private wait;
|
|
9
11
|
protected ackWait: number;
|
|
10
12
|
constructor(client: MsgClientInterface);
|
|
11
13
|
subscriptionOptions(): EventSubOptions;
|
|
12
14
|
listen(): void;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
checkMessages(msg?: Message): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
13
23
|
stop(): void;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param msg
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
14
29
|
private parseMessage;
|
|
15
30
|
}
|
|
16
31
|
//# sourceMappingURL=base-listener.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-listener.d.ts","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAA2C,iBAAiB,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1E,8BAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK;IAE5C,QAAQ,CAAC,OAAO,EAAS,CAAC,CAAC,SAAS,CAAC,CAAC;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,YAAY,CAAmC;IAEvD,SAAS,CAAC,OAAO,EAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"base-listener.d.ts","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAA2C,iBAAiB,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1E,8BAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK;IAE5C,QAAQ,CAAC,OAAO,EAAS,CAAC,CAAC,SAAS,CAAC,CAAC;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,YAAY,CAAmC;IAEvD,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,IAAI,CAA+B;IAE3C,SAAS,CAAC,OAAO,EAAQ,MAAM,CAAe;gBAEjC,MAAM,EAAE,kBAAkB;IAIvC,mBAAmB,IAAI,eAAe;IAKtC,MAAM,IAAI,IAAI;IAmBd;;;OAGG;IACG,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO;IAkBjC;;OAEG;IACH,IAAI,IAAI,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,YAAY;CAKrB"}
|
|
@@ -4,6 +4,8 @@ exports.Listener = void 0;
|
|
|
4
4
|
const nx_frame_be_1 = require("@nextage/nx-frame-be");
|
|
5
5
|
class Listener {
|
|
6
6
|
constructor(client) {
|
|
7
|
+
this.messageStack = [];
|
|
8
|
+
this.wait = false;
|
|
7
9
|
this.ackWait = 5 * 1000;
|
|
8
10
|
this.client = client;
|
|
9
11
|
}
|
|
@@ -14,14 +16,40 @@ class Listener {
|
|
|
14
16
|
this.subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
15
17
|
this.subscription?.on('message', (msg) => {
|
|
16
18
|
nx_frame_be_1.APP.logger.info(`Message received: ${this.subject} / ${this.queueGroupName} - %o`, msg, (0, nx_frame_be_1.logClassCtx)(this));
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
+
this.messageStack.push(msg);
|
|
20
|
+
this.checkMessages();
|
|
21
|
+
// const parsedData = this.parseMessage(msg);
|
|
22
|
+
// this.onMessage(parsedData, msg);
|
|
19
23
|
});
|
|
20
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
async checkMessages(msg) {
|
|
30
|
+
if (this.wait || !this.messageStack.length || this.messageStack.length > 1)
|
|
31
|
+
return;
|
|
32
|
+
msg = this.messageStack.shift();
|
|
33
|
+
if (!msg)
|
|
34
|
+
return;
|
|
35
|
+
this.wait = true;
|
|
36
|
+
const parsedData = this.parseMessage(msg);
|
|
37
|
+
const res = await this.onMessage(parsedData, msg);
|
|
38
|
+
this.wait = false;
|
|
39
|
+
await this.checkMessages();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
21
44
|
stop() {
|
|
22
45
|
if (this.subscription)
|
|
23
46
|
this.client.unsubscribe(this.subscription);
|
|
24
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param msg
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
25
53
|
parseMessage(msg) {
|
|
26
54
|
const data = msg.getData();
|
|
27
55
|
return typeof data === 'string' ? JSON.parse(data) : JSON.parse(data.toString('utf8'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-listener.js","sourceRoot":"","sources":["../../src/events/base-listener.ts"],"names":[],"mappings":";;;AAAA,sDAAoF;AAKpF,MAAsB,QAAQ;
|
|
1
|
+
{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