@rxdi/nats 0.7.240 → 0.7.241
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/{src/decorators/index.ts → dist/decorators/index.d.ts} +1 -1
- package/dist/decorators/index.js +20 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/nats-call.decorator.d.ts +7 -0
- package/dist/decorators/nats-call.decorator.js +32 -0
- package/dist/decorators/nats-call.decorator.js.map +1 -0
- package/dist/decorators/nats-emit.decorator.d.ts +6 -0
- package/dist/decorators/nats-emit.decorator.js +47 -0
- package/dist/decorators/nats-emit.decorator.js.map +1 -0
- package/dist/decorators/nats-listener.decorator.d.ts +5 -0
- package/dist/decorators/nats-listener.decorator.js +28 -0
- package/dist/decorators/nats-listener.decorator.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -2
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/{src/interfaces/index.ts → dist/interfaces/index.d.ts} +1 -1
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/nats-logger.d.ts +20 -0
- package/dist/interfaces/nats-logger.js +37 -0
- package/dist/interfaces/nats-logger.js.map +1 -0
- package/dist/interfaces/nats-module.config.d.ts +54 -0
- package/dist/interfaces/nats-module.config.js +10 -0
- package/dist/interfaces/nats-module.config.js.map +1 -0
- package/dist/nats.module.d.ts +13 -0
- package/dist/nats.module.js +92 -0
- package/dist/nats.module.js.map +1 -0
- package/{src/services/index.ts → dist/services/index.d.ts} +1 -1
- package/dist/services/index.js +25 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/microservice-registry.service.d.ts +20 -0
- package/dist/services/microservice-registry.service.js +60 -0
- package/dist/services/microservice-registry.service.js.map +1 -0
- package/dist/services/nats-client.service.d.ts +27 -0
- package/dist/services/nats-client.service.js +188 -0
- package/dist/services/nats-client.service.js.map +1 -0
- package/dist/services/nats-listener.host.d.ts +30 -0
- package/dist/services/nats-listener.host.js +128 -0
- package/dist/services/nats-listener.host.js.map +1 -0
- package/dist/services/nats-logger.service.d.ts +11 -0
- package/dist/services/nats-logger.service.js +53 -0
- package/dist/services/nats-logger.service.js.map +1 -0
- package/dist/services/nats-pubsub.class.d.ts +36 -0
- package/dist/services/nats-pubsub.class.js +122 -0
- package/dist/services/nats-pubsub.class.js.map +1 -0
- package/dist/services/nats-pubsub.service.d.ts +19 -0
- package/dist/services/nats-pubsub.service.js +101 -0
- package/dist/services/nats-pubsub.service.js.map +1 -0
- package/dist/services/pubsub-async-iterator.d.ts +21 -0
- package/dist/services/pubsub-async-iterator.js +51 -0
- package/dist/services/pubsub-async-iterator.js.map +1 -0
- package/dist/services/service-discovery.service.d.ts +14 -0
- package/dist/services/service-discovery.service.js +70 -0
- package/dist/services/service-discovery.service.js.map +1 -0
- package/package.json +2 -2
- package/src/decorators/nats-call.decorator.ts +0 -42
- package/src/decorators/nats-emit.decorator.ts +0 -59
- package/src/decorators/nats-listener.decorator.ts +0 -37
- package/src/interfaces/nats-logger.ts +0 -41
- package/src/interfaces/nats-module.config.spec.ts +0 -210
- package/src/interfaces/nats-module.config.ts +0 -61
- package/src/nats-decorators.spec.ts +0 -96
- package/src/nats-logger.spec.ts +0 -171
- package/src/nats.module.ts +0 -86
- package/src/services/microservice-registry.service.ts +0 -56
- package/src/services/nats-client.service.ts +0 -187
- package/src/services/nats-listener.host.ts +0 -132
- package/src/services/nats-logger.service.ts +0 -46
- package/src/services/nats-pubsub.class.ts +0 -152
- package/src/services/nats-pubsub.service.ts +0 -95
- package/src/services/pubsub-async-iterator.spec.ts +0 -78
- package/src/services/pubsub-async-iterator.ts +0 -61
- package/src/services/service-discovery.service.ts +0 -57
- package/tsconfig.json +0 -26
- package/tslint.json +0 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OnInit } from '@rxdi/core';
|
|
2
|
+
import { NatsConnection } from 'nats';
|
|
3
|
+
import { NatsModuleConfiguration } from '../interfaces';
|
|
4
|
+
import { NatsLoggerService } from './nats-logger.service';
|
|
5
|
+
export type RequestHandler = (data: any) => Promise<any>;
|
|
6
|
+
export declare class NatsClientService implements OnInit {
|
|
7
|
+
private config;
|
|
8
|
+
private logger;
|
|
9
|
+
private client;
|
|
10
|
+
private subscriptions;
|
|
11
|
+
private subscriptionId;
|
|
12
|
+
private isConnected;
|
|
13
|
+
private connectionPromise;
|
|
14
|
+
private resolveConnection;
|
|
15
|
+
constructor(config: NatsModuleConfiguration, logger: NatsLoggerService);
|
|
16
|
+
waitForConnection(): Promise<void>;
|
|
17
|
+
OnInit(): void;
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
publish(channel: string, data: any): Promise<void>;
|
|
20
|
+
subscribeRequestHandler(channel: string, handler: RequestHandler, queueGroup?: string): Promise<number>;
|
|
21
|
+
subscribe(channel: string, callback: (msg: any) => void, queueGroup?: string): Promise<number>;
|
|
22
|
+
unsubscribe(subId: number): void;
|
|
23
|
+
request(channel: string, data: any, timeout?: number): Promise<any>;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
isReady(): boolean;
|
|
26
|
+
getClient(): NatsConnection | null;
|
|
27
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.NatsClientService = void 0;
|
|
16
|
+
const core_1 = require("@rxdi/core");
|
|
17
|
+
const nats_1 = require("nats");
|
|
18
|
+
const interfaces_1 = require("../interfaces");
|
|
19
|
+
const nats_logger_service_1 = require("./nats-logger.service");
|
|
20
|
+
let NatsClientService = class NatsClientService {
|
|
21
|
+
constructor(config, logger) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
this.client = null;
|
|
25
|
+
this.subscriptions = new Map();
|
|
26
|
+
this.subscriptionId = 0;
|
|
27
|
+
this.isConnected = false;
|
|
28
|
+
this.connectionPromise = new Promise((resolve) => {
|
|
29
|
+
this.resolveConnection = resolve;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async waitForConnection() {
|
|
33
|
+
return this.connectionPromise;
|
|
34
|
+
}
|
|
35
|
+
OnInit() {
|
|
36
|
+
this.connect().catch((error) => {
|
|
37
|
+
const err = error;
|
|
38
|
+
this.logger.error(`[NatsClientService] Initial connection failed: ${err.message}`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async connect() {
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
|
+
if (this.isConnected) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const options = {
|
|
48
|
+
name: ((_a = this.config) === null || _a === void 0 ? void 0 : _a.name) || 'rxdi-nats-client',
|
|
49
|
+
maxReconnectAttempts: (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.maxReconnectAttempts) !== null && _c !== void 0 ? _c : -1,
|
|
50
|
+
reconnect: true,
|
|
51
|
+
};
|
|
52
|
+
if (((_d = this.config) === null || _d === void 0 ? void 0 : _d.user) && ((_e = this.config) === null || _e === void 0 ? void 0 : _e.pass)) {
|
|
53
|
+
options.user = this.config.user;
|
|
54
|
+
options.pass = this.config.pass;
|
|
55
|
+
}
|
|
56
|
+
let servers = (_f = this.config) === null || _f === void 0 ? void 0 : _f.servers;
|
|
57
|
+
if (!servers || servers.length === 0) {
|
|
58
|
+
servers = [`nats://${((_g = this.config) === null || _g === void 0 ? void 0 : _g.host) || 'localhost'}:${((_h = this.config) === null || _h === void 0 ? void 0 : _h.port) || 4222}`];
|
|
59
|
+
}
|
|
60
|
+
options.servers = servers;
|
|
61
|
+
this.client = await (0, nats_1.connect)(options);
|
|
62
|
+
this.isConnected = true;
|
|
63
|
+
this.resolveConnection();
|
|
64
|
+
this.logger.info(`[NatsClientService] Connected to NATS!`);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const err = error;
|
|
68
|
+
this.logger.error(`[NatsClientService] Connection failed: ${err.message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async publish(channel, data) {
|
|
72
|
+
if (!this.client) {
|
|
73
|
+
this.logger.warn('[NatsClientService] Client not connected');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
77
|
+
this.client.publish(channel, message);
|
|
78
|
+
this.logger.debug(`[NatsClientService] Published to ${channel}:`, data);
|
|
79
|
+
}
|
|
80
|
+
async subscribeRequestHandler(channel, handler, queueGroup) {
|
|
81
|
+
if (!this.client) {
|
|
82
|
+
this.logger.warn('[NatsClientService] Client not connected');
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
const sub = this.client.subscribe(channel, { queue: queueGroup });
|
|
86
|
+
const id = ++this.subscriptionId;
|
|
87
|
+
this.subscriptions.set(id, { sub, handler });
|
|
88
|
+
(async () => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
try {
|
|
91
|
+
for await (const msg of sub) {
|
|
92
|
+
try {
|
|
93
|
+
const data = msg.data ? JSON.parse(msg.data.toString()) : null;
|
|
94
|
+
const result = await handler(data);
|
|
95
|
+
if (msg.reply) {
|
|
96
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.publish(msg.reply, JSON.stringify(result));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
this.logger.error(`[NatsClientService] Request handler error on ${channel}:`, e);
|
|
101
|
+
if (msg.reply) {
|
|
102
|
+
(_b = this.client) === null || _b === void 0 ? void 0 : _b.publish(msg.reply, JSON.stringify({ error: String(e) }));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (_c) {
|
|
108
|
+
// Subscription closed
|
|
109
|
+
}
|
|
110
|
+
})();
|
|
111
|
+
this.logger.debug(`[NatsClientService] Subscribed request handler: ${channel}${queueGroup ? ` (queue: ${queueGroup})` : ''}`);
|
|
112
|
+
return id;
|
|
113
|
+
}
|
|
114
|
+
async subscribe(channel, callback, queueGroup) {
|
|
115
|
+
if (!this.client) {
|
|
116
|
+
this.logger.warn('[NatsClientService] Client not connected');
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
const sub = this.client.subscribe(channel, { queue: queueGroup });
|
|
120
|
+
const id = ++this.subscriptionId;
|
|
121
|
+
this.subscriptions.set(id, { sub, handler: async (data) => { callback(data); } });
|
|
122
|
+
(async () => {
|
|
123
|
+
try {
|
|
124
|
+
for await (const msg of sub) {
|
|
125
|
+
try {
|
|
126
|
+
const data = msg.data ? JSON.parse(msg.data.toString()) : null;
|
|
127
|
+
callback(data);
|
|
128
|
+
}
|
|
129
|
+
catch (_a) {
|
|
130
|
+
callback(msg.data.toString());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (_b) {
|
|
135
|
+
// Subscription closed
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
138
|
+
this.logger.debug(`[NatsClientService] Subscribed: ${channel}${queueGroup ? ` (queue: ${queueGroup})` : ''}`);
|
|
139
|
+
return id;
|
|
140
|
+
}
|
|
141
|
+
unsubscribe(subId) {
|
|
142
|
+
const entry = this.subscriptions.get(subId);
|
|
143
|
+
if (entry) {
|
|
144
|
+
entry.sub.unsubscribe();
|
|
145
|
+
this.subscriptions.delete(subId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async request(channel, data, timeout = 30000) {
|
|
149
|
+
if (!this.client) {
|
|
150
|
+
throw new Error('NATS client is not connected');
|
|
151
|
+
}
|
|
152
|
+
this.logger.debug(`[NatsClientService] Sending request to ${channel}:`, data);
|
|
153
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
154
|
+
const response = await this.client.request(channel, message, { timeout });
|
|
155
|
+
if (response.data) {
|
|
156
|
+
try {
|
|
157
|
+
const result = JSON.parse(response.data.toString());
|
|
158
|
+
this.logger.debug(`[NatsClientService] Request response from ${channel}:`, result);
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
catch (_a) {
|
|
162
|
+
return response.data.toString();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
async close() {
|
|
168
|
+
if (this.client) {
|
|
169
|
+
await this.client.close();
|
|
170
|
+
this.isConnected = false;
|
|
171
|
+
this.client = null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
isReady() {
|
|
175
|
+
return this.isConnected && !!this.client;
|
|
176
|
+
}
|
|
177
|
+
getClient() {
|
|
178
|
+
return this.client;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
exports.NatsClientService = NatsClientService;
|
|
182
|
+
exports.NatsClientService = NatsClientService = __decorate([
|
|
183
|
+
(0, core_1.Injectable)(),
|
|
184
|
+
__param(0, (0, core_1.Inject)(interfaces_1.NATS_MODULE_CONFIG)),
|
|
185
|
+
__param(1, (0, core_1.Inject)(interfaces_1.NATS_LOGGER)),
|
|
186
|
+
__metadata("design:paramtypes", [Object, nats_logger_service_1.NatsLoggerService])
|
|
187
|
+
], NatsClientService);
|
|
188
|
+
//# sourceMappingURL=nats-client.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats-client.service.js","sourceRoot":"","sources":["../../src/services/nats-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qCAAwD;AACxD,+BAAgF;AAChF,8CAAyF;AACzF,+DAA0D;AAKnD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAQ5B,YAC8B,MAAuC,EAC9C,MAAiC;QADlB,WAAM,GAAN,MAAM,CAAyB;QACtC,WAAM,GAAN,MAAM,CAAmB;QAThD,WAAM,GAA0B,IAAI,CAAC;QACrC,kBAAa,GAAgE,IAAI,GAAG,EAAE,CAAC;QACvF,mBAAc,GAAG,CAAC,CAAC;QACnB,gBAAW,GAAG,KAAK,CAAC;QAQ1B,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC/C,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACtC,MAAM,GAAG,GAAG,KAAc,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kDAAkD,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACrF,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO;;QACX,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAsB;gBACjC,IAAI,EAAE,CAAA,MAAA,IAAI,CAAC,MAAM,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CAAC,MAAM,CAAC;IACrB,CAAC;CACF,CAAA;AAlLY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,iBAAU,GAAE;IAUR,WAAA,IAAA,aAAM,EAAC,+BAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,aAAM,EAAC,wBAAW,CAAC,CAAA;6CAAiB,uCAAiB;GAV7C,iBAAiB,CAkL7B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OnInit } from '@rxdi/core';
|
|
2
|
+
import { NatsLoggerService } from './nats-logger.service';
|
|
3
|
+
export interface CallEntry {
|
|
4
|
+
targetClass: Function;
|
|
5
|
+
methodName: string;
|
|
6
|
+
channel: string;
|
|
7
|
+
timeout: number;
|
|
8
|
+
queueGroup?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ListenerEntry {
|
|
11
|
+
targetClass: Function;
|
|
12
|
+
methodName: string;
|
|
13
|
+
channel: string;
|
|
14
|
+
queueGroup?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class NatsListenerHost implements OnInit {
|
|
17
|
+
private logger;
|
|
18
|
+
private static callEntries;
|
|
19
|
+
private static listenerEntries;
|
|
20
|
+
private static initialized;
|
|
21
|
+
private static connectionReady;
|
|
22
|
+
constructor(logger: NatsLoggerService);
|
|
23
|
+
static registerCall(targetClass: Function, methodName: string, channel: string, timeout: number, queueGroup?: string): void;
|
|
24
|
+
static registerListener(targetClass: Function, methodName: string, channel: string, queueGroup?: string): void;
|
|
25
|
+
OnInit(): void;
|
|
26
|
+
private setupWithRetry;
|
|
27
|
+
private setupAll;
|
|
28
|
+
private setupCallHandlers;
|
|
29
|
+
private setupListenerHandlers;
|
|
30
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var NatsListenerHost_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NatsListenerHost = void 0;
|
|
17
|
+
const core_1 = require("@rxdi/core");
|
|
18
|
+
const nats_client_service_1 = require("./nats-client.service");
|
|
19
|
+
const interfaces_1 = require("../interfaces");
|
|
20
|
+
const nats_logger_service_1 = require("./nats-logger.service");
|
|
21
|
+
const core_2 = require("@rxdi/core");
|
|
22
|
+
let NatsListenerHost = NatsListenerHost_1 = class NatsListenerHost {
|
|
23
|
+
constructor(logger) {
|
|
24
|
+
this.logger = logger;
|
|
25
|
+
}
|
|
26
|
+
static registerCall(targetClass, methodName, channel, timeout, queueGroup) {
|
|
27
|
+
NatsListenerHost_1.callEntries.push({ targetClass, methodName, channel, timeout, queueGroup });
|
|
28
|
+
}
|
|
29
|
+
static registerListener(targetClass, methodName, channel, queueGroup) {
|
|
30
|
+
NatsListenerHost_1.listenerEntries.push({ targetClass, methodName, channel, queueGroup });
|
|
31
|
+
}
|
|
32
|
+
OnInit() {
|
|
33
|
+
this.logger.debug('[NatsListenerHost] Initializing...');
|
|
34
|
+
this.setupWithRetry();
|
|
35
|
+
}
|
|
36
|
+
setupWithRetry(maxRetries = 30, retryDelayMs = 100) {
|
|
37
|
+
let retries = 0;
|
|
38
|
+
const trySetup = () => {
|
|
39
|
+
try {
|
|
40
|
+
const natsClient = core_2.Container.get(nats_client_service_1.NatsClientService);
|
|
41
|
+
if (!natsClient.isReady()) {
|
|
42
|
+
if (retries < maxRetries) {
|
|
43
|
+
retries++;
|
|
44
|
+
setTimeout(trySetup, retryDelayMs);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.logger.error('[NatsListenerHost] Max retries reached, NATS client not ready');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!NatsListenerHost_1.connectionReady) {
|
|
51
|
+
NatsListenerHost_1.connectionReady = true;
|
|
52
|
+
this.setupAll(natsClient);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
this.logger.error('[NatsListenerHost] Error:', e);
|
|
57
|
+
if (retries < maxRetries) {
|
|
58
|
+
retries++;
|
|
59
|
+
setTimeout(trySetup, retryDelayMs);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
trySetup();
|
|
64
|
+
}
|
|
65
|
+
setupAll(natsClient) {
|
|
66
|
+
if (NatsListenerHost_1.initialized) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.logger.info('[NatsListenerHost] Setting up all handlers...');
|
|
70
|
+
this.setupCallHandlers(natsClient);
|
|
71
|
+
this.setupListenerHandlers(natsClient);
|
|
72
|
+
NatsListenerHost_1.initialized = true;
|
|
73
|
+
this.logger.info('[NatsListenerHost] All handlers subscribed');
|
|
74
|
+
}
|
|
75
|
+
setupCallHandlers(natsClient) {
|
|
76
|
+
for (const entry of NatsListenerHost_1.callEntries) {
|
|
77
|
+
try {
|
|
78
|
+
const instance = core_2.Container.get(entry.targetClass);
|
|
79
|
+
this.logger.info(`[@NatsCall] Subscribing request handler: ${entry.channel} -> ${instance.constructor.name}.${entry.methodName}${entry.queueGroup ? ` (queue: ${entry.queueGroup})` : ''}`);
|
|
80
|
+
natsClient.subscribeRequestHandler(entry.channel, async (request) => {
|
|
81
|
+
try {
|
|
82
|
+
this.logger.debug(`[@NatsCall] Received request on ${entry.channel}:`, request);
|
|
83
|
+
const result = await instance[entry.methodName](request);
|
|
84
|
+
this.logger.debug(`[@NatsCall] Handler result for ${entry.channel}:`, result);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
this.logger.error(`[@NatsCall] Error in handler ${entry.methodName}:`, e);
|
|
89
|
+
return { error: e.message };
|
|
90
|
+
}
|
|
91
|
+
}, entry.queueGroup);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
this.logger.error(`[@NatsCall] Could not get instance of ${entry.targetClass.name}:`, e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
setupListenerHandlers(natsClient) {
|
|
99
|
+
for (const entry of NatsListenerHost_1.listenerEntries) {
|
|
100
|
+
try {
|
|
101
|
+
const instance = core_2.Container.get(entry.targetClass);
|
|
102
|
+
this.logger.info(`[@NatsListener] Subscribing: ${entry.channel} -> ${instance.constructor.name}.${entry.methodName}${entry.queueGroup ? ` (queue: ${entry.queueGroup})` : ''}`);
|
|
103
|
+
natsClient.subscribe(entry.channel, async (data) => {
|
|
104
|
+
try {
|
|
105
|
+
await instance[entry.methodName](data);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.logger.error(`[@NatsListener] Error calling ${entry.methodName}:`, e);
|
|
109
|
+
}
|
|
110
|
+
}, entry.queueGroup);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
this.logger.error(`[@NatsListener] Could not get instance of ${entry.targetClass.name}:`, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.NatsListenerHost = NatsListenerHost;
|
|
119
|
+
NatsListenerHost.callEntries = [];
|
|
120
|
+
NatsListenerHost.listenerEntries = [];
|
|
121
|
+
NatsListenerHost.initialized = false;
|
|
122
|
+
NatsListenerHost.connectionReady = false;
|
|
123
|
+
exports.NatsListenerHost = NatsListenerHost = NatsListenerHost_1 = __decorate([
|
|
124
|
+
(0, core_1.Injectable)(),
|
|
125
|
+
__param(0, (0, core_1.Inject)(interfaces_1.NATS_LOGGER)),
|
|
126
|
+
__metadata("design:paramtypes", [nats_logger_service_1.NatsLoggerService])
|
|
127
|
+
], NatsListenerHost);
|
|
128
|
+
//# sourceMappingURL=nats-listener.host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats-listener.host.js","sourceRoot":"","sources":["../../src/services/nats-listener.host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qCAAwD;AACxD,+DAA0D;AAC1D,8CAA4C;AAC5C,+DAA0D;AAC1D,qCAAuC;AAkBhC,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAM3B,YAC+B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;IACrD,CAAC;IAEJ,MAAM,CAAC,YAAY,CAAC,WAAqB,EAAE,UAAkB,EAAE,OAAe,EAAE,OAAe,EAAE,UAAmB;QAClH,kBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAC/F,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,WAAqB,EAAE,UAAkB,EAAE,OAAe,EAAE,UAAmB;QACrG,kBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAEO,cAAc,CAAC,UAAU,GAAG,EAAE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,AAAlB,CAAmB;AAC9B,gCAAe,GAAoB,EAAE,AAAtB,CAAuB;AACtC,4BAAW,GAAG,KAAK,AAAR,CAAS;AACpB,gCAAe,GAAG,KAAK,AAAR,CAAS;2BAJ5B,gBAAgB;IAD5B,IAAA,iBAAU,GAAE;IAQR,WAAA,IAAA,aAAM,EAAC,wBAAW,CAAC,CAAA;qCAAiB,uCAAiB;GAP7C,gBAAgB,CA6G5B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NatsLogger } from '../interfaces/nats-logger';
|
|
2
|
+
export declare class NatsLoggerService {
|
|
3
|
+
private logger;
|
|
4
|
+
private enabled;
|
|
5
|
+
constructor(enabled?: boolean, logger?: NatsLogger);
|
|
6
|
+
setEnabled(enabled: boolean): void;
|
|
7
|
+
debug(message: string, ...args: any[]): void;
|
|
8
|
+
info(message: string, ...args: any[]): void;
|
|
9
|
+
warn(message: string, ...args: any[]): void;
|
|
10
|
+
error(message: string, ...args: any[]): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NatsLoggerService = void 0;
|
|
13
|
+
const core_1 = require("@rxdi/core");
|
|
14
|
+
let NatsLoggerService = class NatsLoggerService {
|
|
15
|
+
constructor(enabled = false, logger) {
|
|
16
|
+
this.enabled = enabled;
|
|
17
|
+
this.logger = logger || {
|
|
18
|
+
debug: () => { },
|
|
19
|
+
info: () => { },
|
|
20
|
+
warn: () => { },
|
|
21
|
+
error: () => { },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
setEnabled(enabled) {
|
|
25
|
+
this.enabled = enabled;
|
|
26
|
+
}
|
|
27
|
+
debug(message, ...args) {
|
|
28
|
+
if (this.enabled) {
|
|
29
|
+
this.logger.debug(message, ...args);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
info(message, ...args) {
|
|
33
|
+
if (this.enabled) {
|
|
34
|
+
this.logger.info(message, ...args);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
warn(message, ...args) {
|
|
38
|
+
if (this.enabled) {
|
|
39
|
+
this.logger.warn(message, ...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
error(message, ...args) {
|
|
43
|
+
if (this.enabled) {
|
|
44
|
+
this.logger.error(message, ...args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.NatsLoggerService = NatsLoggerService;
|
|
49
|
+
exports.NatsLoggerService = NatsLoggerService = __decorate([
|
|
50
|
+
(0, core_1.Injectable)(),
|
|
51
|
+
__metadata("design:paramtypes", [Boolean, Object])
|
|
52
|
+
], NatsLoggerService);
|
|
53
|
+
//# sourceMappingURL=nats-logger.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats-logger.service.js","sourceRoot":"","sources":["../../src/services/nats-logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAwC;AAIjC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI5B,YAAY,UAAmB,KAAK,EAAE,MAAmB;QACvD,IAAI,CAAC,O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interfaces';
|
|
2
|
+
export declare class NatsPubSub implements NatsPubSubInterface {
|
|
3
|
+
private subscriptionMap;
|
|
4
|
+
private subsRefsMap;
|
|
5
|
+
private currentSubscriptionId;
|
|
6
|
+
private unsubscribeMap;
|
|
7
|
+
private subscriptionIds;
|
|
8
|
+
private natsClient;
|
|
9
|
+
constructor(natsClient: NatsClientInterface);
|
|
10
|
+
publish(trigger: string, payload: any): Promise<void>;
|
|
11
|
+
subscribe<T>(trigger: string, onMessage: (m: T) => Promise<void>, config?: any): Promise<number>;
|
|
12
|
+
unsubscribe(subId: number): Promise<void>;
|
|
13
|
+
asyncIterator<T>(triggers: string | string[]): AsyncIterator<T>;
|
|
14
|
+
asyncIterableIterator<T>(triggers: string | string[]): AsyncIterator<T>;
|
|
15
|
+
}
|
|
16
|
+
export declare class NatsPubSubAsyncIterator<T> implements AsyncIterator<T> {
|
|
17
|
+
private pubsub;
|
|
18
|
+
private triggers;
|
|
19
|
+
private subscriptionId;
|
|
20
|
+
private listeners;
|
|
21
|
+
private resolveReturn;
|
|
22
|
+
private rejectPromise;
|
|
23
|
+
private returnPromise;
|
|
24
|
+
constructor(pubsub: NatsPubSubInterface, triggers: string | string[]);
|
|
25
|
+
next(): Promise<{
|
|
26
|
+
value: T;
|
|
27
|
+
done: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
return(): Promise<{
|
|
30
|
+
value: T;
|
|
31
|
+
done: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
throw?(error?: any): Promise<never>;
|
|
34
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createNatsPubSub(natsClient: NatsClientInterface): NatsPubSub;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsPubSubAsyncIterator = exports.NatsPubSub = void 0;
|
|
4
|
+
exports.createNatsPubSub = createNatsPubSub;
|
|
5
|
+
class NatsPubSub {
|
|
6
|
+
constructor(natsClient) {
|
|
7
|
+
this.subscriptionMap = new Map();
|
|
8
|
+
this.subsRefsMap = new Map();
|
|
9
|
+
this.currentSubscriptionId = 0;
|
|
10
|
+
this.unsubscribeMap = new Map();
|
|
11
|
+
this.subscriptionIds = new Map();
|
|
12
|
+
this.natsClient = natsClient;
|
|
13
|
+
}
|
|
14
|
+
async publish(trigger, payload) {
|
|
15
|
+
await this.natsClient.publish(trigger, payload);
|
|
16
|
+
}
|
|
17
|
+
async subscribe(trigger, onMessage, config) {
|
|
18
|
+
const id = this.currentSubscriptionId++;
|
|
19
|
+
this.subscriptionMap.set(id, [trigger, onMessage]);
|
|
20
|
+
const refs = this.subsRefsMap.get(trigger);
|
|
21
|
+
if (refs === null || refs === void 0 ? void 0 : refs.length) {
|
|
22
|
+
this.subsRefsMap.set(trigger, [...refs, id]);
|
|
23
|
+
return id;
|
|
24
|
+
}
|
|
25
|
+
const subId = await this.natsClient.subscribe(trigger, async (msg) => {
|
|
26
|
+
const subscribers = this.subsRefsMap.get(trigger);
|
|
27
|
+
if (!(subscribers === null || subscribers === void 0 ? void 0 : subscribers.length))
|
|
28
|
+
return;
|
|
29
|
+
for (const sId of subscribers) {
|
|
30
|
+
const entry = this.subscriptionMap.get(sId);
|
|
31
|
+
if (!entry)
|
|
32
|
+
continue;
|
|
33
|
+
const [, listener] = entry;
|
|
34
|
+
await listener(msg);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this.subscriptionIds.set(trigger, subId);
|
|
38
|
+
this.subsRefsMap.set(trigger, [id]);
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
async unsubscribe(subId) {
|
|
42
|
+
const entry = this.subscriptionMap.get(subId);
|
|
43
|
+
const triggerName = entry === null || entry === void 0 ? void 0 : entry[0];
|
|
44
|
+
if (!triggerName) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const refs = this.subsRefsMap.get(triggerName);
|
|
48
|
+
if (!refs)
|
|
49
|
+
return;
|
|
50
|
+
if (refs.length === 1) {
|
|
51
|
+
const natsSubId = this.subscriptionIds.get(triggerName);
|
|
52
|
+
if (natsSubId !== undefined) {
|
|
53
|
+
this.natsClient.unsubscribe(natsSubId);
|
|
54
|
+
this.subscriptionIds.delete(triggerName);
|
|
55
|
+
}
|
|
56
|
+
this.unsubscribeMap.delete(triggerName);
|
|
57
|
+
this.subsRefsMap.delete(triggerName);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.subsRefsMap.set(triggerName, refs.filter((id) => id !== subId));
|
|
61
|
+
}
|
|
62
|
+
this.subscriptionMap.delete(subId);
|
|
63
|
+
}
|
|
64
|
+
asyncIterator(triggers) {
|
|
65
|
+
return new NatsPubSubAsyncIterator(this, triggers);
|
|
66
|
+
}
|
|
67
|
+
asyncIterableIterator(triggers) {
|
|
68
|
+
return new NatsPubSubAsyncIterator(this, triggers);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.NatsPubSub = NatsPubSub;
|
|
72
|
+
class NatsPubSubAsyncIterator {
|
|
73
|
+
constructor(pubsub, triggers) {
|
|
74
|
+
this.pubsub = pubsub;
|
|
75
|
+
this.triggers = triggers;
|
|
76
|
+
this.subscriptionId = null;
|
|
77
|
+
this.listeners = [];
|
|
78
|
+
this.returnPromise = new Promise((resolve, reject) => {
|
|
79
|
+
this.resolveReturn = resolve;
|
|
80
|
+
this.rejectPromise = reject;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async next() {
|
|
84
|
+
if (!this.subscriptionId) {
|
|
85
|
+
const trigger = Array.isArray(this.triggers) ? this.triggers[0] : this.triggers;
|
|
86
|
+
this.subscriptionId = await this.pubsub.subscribe(trigger, async (message) => {
|
|
87
|
+
for (const listener of this.listeners) {
|
|
88
|
+
listener(message);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
const listener = (value) => {
|
|
94
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
95
|
+
resolve({ value, done: false });
|
|
96
|
+
};
|
|
97
|
+
this.listeners.push(listener);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async return() {
|
|
101
|
+
if (this.subscriptionId) {
|
|
102
|
+
await this.pubsub.unsubscribe(this.subscriptionId);
|
|
103
|
+
this.subscriptionId = null;
|
|
104
|
+
}
|
|
105
|
+
return { value: undefined, done: true };
|
|
106
|
+
}
|
|
107
|
+
async throw(error) {
|
|
108
|
+
if (this.subscriptionId) {
|
|
109
|
+
await this.pubsub.unsubscribe(this.subscriptionId);
|
|
110
|
+
this.subscriptionId = null;
|
|
111
|
+
}
|
|
112
|
+
return Promise.reject(error);
|
|
113
|
+
}
|
|
114
|
+
[Symbol.asyncIterator]() {
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.NatsPubSubAsyncIterator = NatsPubSubAsyncIterator;
|
|
119
|
+
function createNatsPubSub(natsClient) {
|
|
120
|
+
return new NatsPubSub(natsClient);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=nats-pubsub.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats-pubsub.class.js","sourceRoot":"","sources":["../../src/services/nats-pubsub.class.ts"],"names":[],"mappings":";;;AAqJA,4CAEC;AArJD,MAAa,UAAU;IAQrB,YAAY,UAA+B;QAPnC,oBAAe,GAAG,IAAI,GAAG,EAA+C,CAAC;QACzE,gBAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC1C,0BAAqB,GAAG,CAAC,CAAC;QAC1B,mBAAc,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC/C,oBAAe,GAAwB,IAAI,GAAG,EAAE,CAAC;QAIvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAe,EAAE,OAAY;QACzC,MAAM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,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;gBAC9D,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAClC,CAAC,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACnD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,SAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,KAAK,CAAE,KAAW;QACtB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACnD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1DD,0DA0DC;AAED,SAAgB,gBAAgB,CAAC,UAA+B;IAC9D,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OnInit } from '@rxdi/core';
|
|
2
|
+
import { NatsClientService } from './nats-client.service';
|
|
3
|
+
import { NatsPubSubInterface } from '../interfaces';
|
|
4
|
+
import { NatsLoggerService } from './nats-logger.service';
|
|
5
|
+
export declare class NatsPubSubService implements NatsPubSubInterface, OnInit {
|
|
6
|
+
private natsClient;
|
|
7
|
+
private logger;
|
|
8
|
+
private subscriptionMap;
|
|
9
|
+
private subsRefsMap;
|
|
10
|
+
private currentSubscriptionId;
|
|
11
|
+
private unsubscribeMap;
|
|
12
|
+
constructor(natsClient: NatsClientService, logger: NatsLoggerService);
|
|
13
|
+
OnInit(): void;
|
|
14
|
+
publish(trigger: string, payload: any): Promise<void>;
|
|
15
|
+
subscribe<T>(trigger: string, onMessage: (m: T) => Promise<void>): Promise<number>;
|
|
16
|
+
unsubscribe(subId: number): Promise<void>;
|
|
17
|
+
asyncIterator<T>(triggers: string | string[]): AsyncIterator<T>;
|
|
18
|
+
asyncIterableIterator<T>(triggers: string | string[]): AsyncIterator<T>;
|
|
19
|
+
}
|