@epztickets/common 1.24.0 → 1.26.0
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.
|
@@ -11,6 +11,6 @@ export declare abstract class JetStreamListener<T extends Event> {
|
|
|
11
11
|
protected js: JetStreamClient;
|
|
12
12
|
constructor(js: JetStreamClient);
|
|
13
13
|
listen(): Promise<void>;
|
|
14
|
-
abstract onMessage(data: T["data"], msg: JsMsg): void
|
|
14
|
+
abstract onMessage(data: T["data"], msg: JsMsg): Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import {
|
|
3
|
+
// JetStreamClient,
|
|
4
|
+
// consumerOpts,
|
|
5
|
+
// JsMsg,
|
|
6
|
+
// } from "nats";
|
|
7
|
+
// import { Subjects } from "./subjects";
|
|
2
8
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
9
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
10
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -17,7 +23,6 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
17
23
|
};
|
|
18
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
25
|
exports.JetStreamListener = void 0;
|
|
20
|
-
const nats_1 = require("nats");
|
|
21
26
|
class JetStreamListener {
|
|
22
27
|
constructor(js) {
|
|
23
28
|
this.js = js;
|
|
@@ -25,24 +30,22 @@ class JetStreamListener {
|
|
|
25
30
|
listen() {
|
|
26
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
32
|
var _a, e_1, _b, _c;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
opts.manualAck();
|
|
31
|
-
opts.ackExplicit();
|
|
32
|
-
opts.deliverAll();
|
|
33
|
-
opts.maxDeliver(5);
|
|
34
|
-
opts.filterSubject(this.subject);
|
|
35
|
-
opts.deliverTo(`${this.queueGroup}.${this.durableName}`);
|
|
36
|
-
const sub = yield this.js.subscribe(this.subject, opts);
|
|
33
|
+
// Get or bind to the durable consumer
|
|
34
|
+
const consumer = yield this.js.consumers.get("events", this.durableName);
|
|
37
35
|
console.log(`Listening for ${this.subject} with durable ${this.durableName}`);
|
|
36
|
+
// Long-running pull-based consumption
|
|
37
|
+
const messages = yield consumer.consume({
|
|
38
|
+
max_messages: 1, // backpressure control
|
|
39
|
+
});
|
|
38
40
|
try {
|
|
39
|
-
for (var _d = true,
|
|
40
|
-
_c =
|
|
41
|
+
for (var _d = true, messages_1 = __asyncValues(messages), messages_1_1; messages_1_1 = yield messages_1.next(), _a = messages_1_1.done, !_a; _d = true) {
|
|
42
|
+
_c = messages_1_1.value;
|
|
41
43
|
_d = false;
|
|
42
44
|
const msg = _c;
|
|
43
45
|
try {
|
|
44
46
|
const data = JSON.parse(msg.data.toString());
|
|
45
47
|
yield this.onMessage(data, msg);
|
|
48
|
+
msg.ack();
|
|
46
49
|
}
|
|
47
50
|
catch (err) {
|
|
48
51
|
console.error("Listener error", err);
|
|
@@ -52,7 +55,7 @@ class JetStreamListener {
|
|
|
52
55
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
53
56
|
finally {
|
|
54
57
|
try {
|
|
55
|
-
if (!_d && !_a && (_b =
|
|
58
|
+
if (!_d && !_a && (_b = messages_1.return)) yield _b.call(messages_1);
|
|
56
59
|
}
|
|
57
60
|
finally { if (e_1) throw e_1.error; }
|
|
58
61
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { JetStreamManager, RetentionPolicy, StorageType, DiscardPolicy } from "nats";
|
|
3
|
-
// import { Streams } from "../events/subjects";
|
|
4
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,81 +10,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
10
|
};
|
|
13
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
12
|
exports.ensureStreams = ensureStreams;
|
|
15
|
-
// export async function ensureEventStream(jsm: JetStreamManager) {
|
|
16
|
-
// const streams = await jsm.streams.list().next();
|
|
17
|
-
// const exists = streams.some(s => s.config.name === Streams.Events);
|
|
18
|
-
// if (exists) {
|
|
19
|
-
// console.log("Stream already exists:", Streams.Events);
|
|
20
|
-
// return};
|
|
21
|
-
// await jsm.streams.add({
|
|
22
|
-
// name: Streams.Events,
|
|
23
|
-
// subjects: ["events.>"],
|
|
24
|
-
// // retention: RetentionPolicy.Workqueue, // consumer needs to be unique
|
|
25
|
-
// retention: RetentionPolicy.Limits, // fan-out to multiple services
|
|
26
|
-
// storage: StorageType.File,
|
|
27
|
-
// discard: DiscardPolicy.Old,
|
|
28
|
-
// max_age: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
29
|
-
// });
|
|
30
|
-
// }
|
|
31
|
-
// import {
|
|
32
|
-
// JetStreamManager,
|
|
33
|
-
// RetentionPolicy,
|
|
34
|
-
// StorageType,
|
|
35
|
-
// DiscardPolicy,
|
|
36
|
-
// } from "nats";
|
|
37
|
-
// import { Streams } from "../events/subjects";
|
|
38
|
-
// export async function ensureStreams(jsm: JetStreamManager) {
|
|
39
|
-
// const existing = await jsm.streams.list().next();
|
|
40
|
-
// const has = (name: string) =>
|
|
41
|
-
// existing.some(s => s.config.name === name);
|
|
42
|
-
// /* ---------------- EVENTS STREAM ---------------- */
|
|
43
|
-
// if (!has(Streams.Events)) {
|
|
44
|
-
// await jsm.streams.add({
|
|
45
|
-
// name: Streams.Events,
|
|
46
|
-
// subjects: ["events.>"],
|
|
47
|
-
// retention: RetentionPolicy.Limits, // FAN-OUT
|
|
48
|
-
// storage: StorageType.File,
|
|
49
|
-
// discard: DiscardPolicy.Old,
|
|
50
|
-
// max_age: 7 * 24 * 60 * 60 * 1000,
|
|
51
|
-
// });
|
|
52
|
-
// console.log("Created stream:", Streams.Events);
|
|
53
|
-
// }
|
|
54
|
-
// /* ---------------- JOBS STREAM ---------------- */
|
|
55
|
-
// if (!has(Streams.Jobs)) {
|
|
56
|
-
// await jsm.streams.add({
|
|
57
|
-
// name: Streams.Jobs,
|
|
58
|
-
// subjects: ["jobs.>"],
|
|
59
|
-
// retention: RetentionPolicy.Workqueue, // EXACTLY-ONCE
|
|
60
|
-
// storage: StorageType.File,
|
|
61
|
-
// discard: DiscardPolicy.Old,
|
|
62
|
-
// });
|
|
63
|
-
// console.log("Created stream:", Streams.Jobs);
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
13
|
const nats_1 = require("nats");
|
|
67
14
|
const subjects_1 = require("../events/subjects");
|
|
68
15
|
function ensureStreams(jsm) {
|
|
69
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
17
|
+
const existing = yield jsm.streams.list().next();
|
|
18
|
+
const has = (name) => existing.some(s => s.config.name === name);
|
|
19
|
+
/* ---------------- EVENTS STREAM ---------------- */
|
|
20
|
+
if (!has(subjects_1.Streams.Events)) {
|
|
21
|
+
yield jsm.streams.add({
|
|
22
|
+
name: subjects_1.Streams.Events,
|
|
23
|
+
subjects: ["events.>"],
|
|
24
|
+
retention: nats_1.RetentionPolicy.Limits, // FAN-OUT
|
|
25
|
+
storage: nats_1.StorageType.File,
|
|
26
|
+
discard: nats_1.DiscardPolicy.Old,
|
|
27
|
+
max_age: 7 * 24 * 60 * 60 * 1000000000,
|
|
28
|
+
});
|
|
29
|
+
console.log("Created stream:", subjects_1.Streams.Events);
|
|
30
|
+
}
|
|
31
|
+
/* ---------------- JOBS STREAM ---------------- */
|
|
32
|
+
if (!has(subjects_1.Streams.Jobs)) {
|
|
33
|
+
yield jsm.streams.add({
|
|
34
|
+
name: subjects_1.Streams.Jobs,
|
|
35
|
+
subjects: ["jobs.>"],
|
|
36
|
+
retention: nats_1.RetentionPolicy.Workqueue, // EXACTLY-ONCE
|
|
37
|
+
storage: nats_1.StorageType.File,
|
|
38
|
+
discard: nats_1.DiscardPolicy.Old,
|
|
39
|
+
});
|
|
40
|
+
console.log("Created stream:", subjects_1.Streams.Jobs);
|
|
80
41
|
}
|
|
81
|
-
// 2️⃣ Stream does not exist → create it
|
|
82
|
-
yield jsm.streams.add({
|
|
83
|
-
name: subjects_1.Streams.Events,
|
|
84
|
-
subjects: ["events.>"],
|
|
85
|
-
retention: nats_1.RetentionPolicy.Limits, // FAN-OUT
|
|
86
|
-
storage: nats_1.StorageType.File,
|
|
87
|
-
discard: nats_1.DiscardPolicy.Old,
|
|
88
|
-
max_age: 7 * 24 * 60 * 60 * 1000,
|
|
89
|
-
});
|
|
90
|
-
console.log("✅ Created EVENTS stream");
|
|
91
42
|
});
|
|
92
43
|
}
|