@heritageai/messaging 1.0.0 → 1.0.2
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/base-listener.d.ts +2 -2
- package/dist/base-listener.js +9 -7
- package/package.json +1 -1
- package/src/base-listener.ts +11 -6
package/dist/base-listener.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Stan, Message } from
|
|
2
|
-
export declare abstract class
|
|
1
|
+
import { Stan, Message } from "node-nats-streaming";
|
|
2
|
+
export declare abstract class Listener<T> {
|
|
3
3
|
abstract subject: string;
|
|
4
4
|
abstract queueGroupName: string;
|
|
5
5
|
abstract onMessage(data: T, msg: Message): void;
|
package/dist/base-listener.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.Listener = void 0;
|
|
4
|
+
class Listener {
|
|
5
5
|
constructor(client) {
|
|
6
6
|
this.client = client;
|
|
7
7
|
}
|
|
@@ -14,11 +14,13 @@ class BaseListener {
|
|
|
14
14
|
}
|
|
15
15
|
listen() {
|
|
16
16
|
const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
subscription.on(
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
// @ts-ignore (node-nats-streaming typing bug)
|
|
18
|
+
subscription.on("message", (msg) => {
|
|
19
|
+
const data = typeof msg.getData() === "string"
|
|
20
|
+
? JSON.parse(msg.getData())
|
|
21
|
+
: JSON.parse(msg.getData().toString("utf8"));
|
|
22
|
+
this.onMessage(data, msg);
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
exports.
|
|
26
|
+
exports.Listener = Listener;
|
package/package.json
CHANGED
package/src/base-listener.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Stan, Message } from
|
|
1
|
+
import { Stan, Message } from "node-nats-streaming";
|
|
2
2
|
|
|
3
|
-
export abstract class
|
|
3
|
+
export abstract class Listener<T> {
|
|
4
4
|
abstract subject: string;
|
|
5
5
|
abstract queueGroupName: string;
|
|
6
6
|
abstract onMessage(data: T, msg: Message): void;
|
|
7
|
+
|
|
7
8
|
protected client: Stan;
|
|
8
9
|
|
|
9
10
|
constructor(client: Stan) {
|
|
@@ -25,10 +26,14 @@ export abstract class BaseListener<T> {
|
|
|
25
26
|
this.subscriptionOptions()
|
|
26
27
|
);
|
|
27
28
|
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
subscription.on(
|
|
30
|
-
const
|
|
31
|
-
|
|
29
|
+
// @ts-ignore (node-nats-streaming typing bug)
|
|
30
|
+
subscription.on("message", (msg: Message) => {
|
|
31
|
+
const data =
|
|
32
|
+
typeof msg.getData() === "string"
|
|
33
|
+
? JSON.parse(msg.getData())
|
|
34
|
+
: JSON.parse(msg.getData().toString("utf8"));
|
|
35
|
+
|
|
36
|
+
this.onMessage(data, msg);
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
}
|