@fluojs/microservices 1.0.0-beta.6 → 1.0.1
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/transports/redis-streams-transport.d.ts +1 -0
- package/dist/transports/redis-streams-transport.d.ts.map +1 -1
- package/dist/transports/redis-streams-transport.js +59 -39
- package/dist/transports/redis-transport.d.ts +2 -0
- package/dist/transports/redis-transport.d.ts.map +1 -1
- package/dist/transports/redis-transport.js +37 -14
- package/package.json +4 -4
|
@@ -56,6 +56,7 @@ export interface RedisStreamsMicroserviceTransportOptions {
|
|
|
56
56
|
*/
|
|
57
57
|
export declare class RedisStreamsMicroserviceTransport implements MicroserviceTransport {
|
|
58
58
|
private readonly options;
|
|
59
|
+
private closePromise;
|
|
59
60
|
private closing;
|
|
60
61
|
private readonly consumerId;
|
|
61
62
|
private handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-streams-transport.d.ts","sourceRoot":"","sources":["../../src/transports/redis-streams-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGxG,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED,wEAAwE;AACxE,MAAM,WAAW,uBAAuB;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,mGAAmG;AACnG,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzG,UAAU,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,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAoFrF;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB5D;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAyEd,mBAAmB;YAanB,yBAAyB;YAyBzB,wBAAwB;YA8BxB,UAAU;YAoCV,iBAAiB;YAcjB,oBAAoB;YA4CpB,YAAY;YAeZ,wBAAwB;YAQxB,kBAAkB;IAuBhC,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,WAAW;IAgCnB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,KAAK,aAAa,GAExB;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,YAAY,GAEvB;IAED,OAAO,KAAK,oBAAoB,GAE/B;IAED,OAAO,KAAK,uBAAuB,GAElC;IAED,OAAO,KAAK,UAAU,GAErB;IAED,OAAO,KAAK,aAAa,GAExB;CACF"}
|
|
@@ -19,6 +19,7 @@ function delay(ms) {
|
|
|
19
19
|
* at-least-once delivery with request timeouts while preserving Fluo's transport abstraction.
|
|
20
20
|
*/
|
|
21
21
|
export class RedisStreamsMicroserviceTransport {
|
|
22
|
+
closePromise;
|
|
22
23
|
closing = false;
|
|
23
24
|
consumerId;
|
|
24
25
|
handler;
|
|
@@ -64,7 +65,12 @@ export class RedisStreamsMicroserviceTransport {
|
|
|
64
65
|
* @returns A promise that resolves once all stream consumers are initialized.
|
|
65
66
|
*/
|
|
66
67
|
async listen(handler) {
|
|
67
|
-
this.closing
|
|
68
|
+
if (this.closing) {
|
|
69
|
+
if (this.closePromise) {
|
|
70
|
+
throw new Error('RedisStreamsMicroserviceTransport is closing. Wait for close() to complete before listen().');
|
|
71
|
+
}
|
|
72
|
+
this.closing = false;
|
|
73
|
+
}
|
|
68
74
|
this.handler = handler;
|
|
69
75
|
if (this.listening) {
|
|
70
76
|
return;
|
|
@@ -175,6 +181,9 @@ export class RedisStreamsMicroserviceTransport {
|
|
|
175
181
|
* @returns A promise that resolves once the event frame is appended to the stream.
|
|
176
182
|
*/
|
|
177
183
|
async emit(pattern, payload) {
|
|
184
|
+
if (this.closing) {
|
|
185
|
+
throw new Error('RedisStreamsMicroserviceTransport is closing. Wait for close() to complete before emit().');
|
|
186
|
+
}
|
|
178
187
|
const frame = {
|
|
179
188
|
kind: 'event',
|
|
180
189
|
pattern,
|
|
@@ -193,53 +202,64 @@ export class RedisStreamsMicroserviceTransport {
|
|
|
193
202
|
* @returns A promise that resolves once shutdown cleanup finishes.
|
|
194
203
|
*/
|
|
195
204
|
async close() {
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
await this.listenPromise;
|
|
205
|
+
if (this.closePromise) {
|
|
206
|
+
await this.closePromise;
|
|
207
|
+
return;
|
|
200
208
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
closeError ??= result.reason;
|
|
207
|
-
}
|
|
209
|
+
this.closing = true;
|
|
210
|
+
this.closePromise = (async () => {
|
|
211
|
+
let closeError;
|
|
212
|
+
if (this.listenPromise) {
|
|
213
|
+
await this.listenPromise;
|
|
208
214
|
}
|
|
209
|
-
|
|
215
|
+
try {
|
|
216
|
+
const settled = await Promise.allSettled(this.pollPromises);
|
|
217
|
+
const shouldDestroyMessageGroup = await this.releaseMessageGroupLease();
|
|
218
|
+
for (const result of settled) {
|
|
219
|
+
if (result.status === 'rejected') {
|
|
220
|
+
closeError ??= result.reason;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (shouldDestroyMessageGroup) {
|
|
224
|
+
try {
|
|
225
|
+
await this.options.readerClient.xgroupDestroy(this.messageStream, this.messageGroup);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
closeError ??= error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
210
230
|
try {
|
|
211
|
-
await this.options.readerClient.xgroupDestroy(this.
|
|
231
|
+
await this.options.readerClient.xgroupDestroy(this.eventStream, this.eventGroup);
|
|
212
232
|
} catch (error) {
|
|
213
233
|
closeError ??= error;
|
|
214
234
|
}
|
|
235
|
+
try {
|
|
236
|
+
await this.options.readerClient.xgroupDestroy(this.responseStream, this.responseGroup);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
closeError ??= error;
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
await this.options.readerClient.del?.(this.responseStream);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
closeError ??= error;
|
|
244
|
+
}
|
|
245
|
+
} finally {
|
|
246
|
+
this.listening = false;
|
|
247
|
+
this.handler = undefined;
|
|
248
|
+
this.messageGroupLeaseRegistered = false;
|
|
249
|
+
this.ownsMessageGroup = false;
|
|
250
|
+
this.pollPromises = [];
|
|
251
|
+
for (const pending of [...this.pending.values()]) {
|
|
252
|
+
pending.reject(new Error('Redis Streams microservice transport closed before response.'));
|
|
253
|
+
}
|
|
215
254
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
} catch (error) {
|
|
219
|
-
closeError ??= error;
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
await this.options.readerClient.xgroupDestroy(this.responseStream, this.responseGroup);
|
|
223
|
-
} catch (error) {
|
|
224
|
-
closeError ??= error;
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
await this.options.readerClient.del?.(this.responseStream);
|
|
228
|
-
} catch (error) {
|
|
229
|
-
closeError ??= error;
|
|
255
|
+
if (closeError) {
|
|
256
|
+
throw closeError;
|
|
230
257
|
}
|
|
258
|
+
})();
|
|
259
|
+
try {
|
|
260
|
+
await this.closePromise;
|
|
231
261
|
} finally {
|
|
232
|
-
this.
|
|
233
|
-
this.handler = undefined;
|
|
234
|
-
this.messageGroupLeaseRegistered = false;
|
|
235
|
-
this.ownsMessageGroup = false;
|
|
236
|
-
this.pollPromises = [];
|
|
237
|
-
for (const pending of [...this.pending.values()]) {
|
|
238
|
-
pending.reject(new Error('Redis Streams microservice transport closed before response.'));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (closeError) {
|
|
242
|
-
throw closeError;
|
|
262
|
+
this.closePromise = undefined;
|
|
243
263
|
}
|
|
244
264
|
}
|
|
245
265
|
async ensureConsumerGroup(stream, group) {
|
|
@@ -21,6 +21,8 @@ export interface RedisPubSubMicroserviceTransportOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare class RedisPubSubMicroserviceTransport implements MicroserviceTransport {
|
|
23
23
|
private readonly options;
|
|
24
|
+
private closePromise;
|
|
25
|
+
private closing;
|
|
24
26
|
private handler;
|
|
25
27
|
private logger;
|
|
26
28
|
private listening;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-transport.d.ts","sourceRoot":"","sources":["../../src/transports/redis-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASxG,UAAU,SAAS;IACjB,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC;IACtF,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC;IACpF,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,SAAS,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,WAAW,CAAC,GAAG,QAAQ,EAAE,M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Aa,gCAAiC,YAAW,qBAAqB;IAqBhE,OAAO,CAAC,QAAQ,CAAC,OAAO;IApBpC,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAE9B;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,sBAAsB;IAI9B;;;;OAIG;gBAC0B,OAAO,EAAE,uCAAuC;IAI7E,SAAS,CAAC,MAAM,EAAE,2BAA2B,GAAG,IAAI;IAIpD;;;;;OAKG;IACG,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuCtD;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5D;;;;;;;;OAQG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOrF;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAsCd,cAAc;IA4B5B,OAAO,KAAK,YAAY,GAEvB;CACF"}
|
|
@@ -9,6 +9,8 @@ import { logTransportEventHandlerFailure } from './event-handler-logger.js';
|
|
|
9
9
|
* a transport with durable reply semantics such as TCP, Kafka, or Redis Streams.
|
|
10
10
|
*/
|
|
11
11
|
export class RedisPubSubMicroserviceTransport {
|
|
12
|
+
closePromise;
|
|
13
|
+
closing = false;
|
|
12
14
|
handler;
|
|
13
15
|
logger;
|
|
14
16
|
listening = false;
|
|
@@ -41,6 +43,12 @@ export class RedisPubSubMicroserviceTransport {
|
|
|
41
43
|
* @returns A promise that resolves once the Redis subscription is active.
|
|
42
44
|
*/
|
|
43
45
|
async listen(handler) {
|
|
46
|
+
if (this.closing) {
|
|
47
|
+
if (this.closePromise) {
|
|
48
|
+
throw new Error('RedisPubSubMicroserviceTransport is closing. Wait for close() to complete before listen().');
|
|
49
|
+
}
|
|
50
|
+
this.closing = false;
|
|
51
|
+
}
|
|
44
52
|
this.handler = handler;
|
|
45
53
|
if (this.listening) {
|
|
46
54
|
return;
|
|
@@ -74,6 +82,9 @@ export class RedisPubSubMicroserviceTransport {
|
|
|
74
82
|
* @returns A promise that resolves once Redis accepts the publication.
|
|
75
83
|
*/
|
|
76
84
|
async emit(pattern, payload) {
|
|
85
|
+
if (this.closing) {
|
|
86
|
+
throw new Error('RedisPubSubMicroserviceTransport is closing. Wait for close() to complete before emit().');
|
|
87
|
+
}
|
|
77
88
|
const message = {
|
|
78
89
|
kind: 'event',
|
|
79
90
|
pattern,
|
|
@@ -104,23 +115,35 @@ export class RedisPubSubMicroserviceTransport {
|
|
|
104
115
|
* @returns A promise that resolves once shutdown cleanup completes.
|
|
105
116
|
*/
|
|
106
117
|
async close() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
if (this.closePromise) {
|
|
119
|
+
await this.closePromise;
|
|
120
|
+
return;
|
|
110
121
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
this.closing = true;
|
|
123
|
+
this.closePromise = (async () => {
|
|
124
|
+
let closeError;
|
|
125
|
+
if (this.listenPromise) {
|
|
126
|
+
await this.listenPromise;
|
|
114
127
|
}
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
try {
|
|
129
|
+
if (this.listening) {
|
|
130
|
+
await this.options.subscribeClient.unsubscribe(this.eventChannel);
|
|
131
|
+
}
|
|
132
|
+
} catch (error) {
|
|
133
|
+
closeError = error;
|
|
134
|
+
} finally {
|
|
135
|
+
this.options.subscribeClient.off?.('message', this.messageListener);
|
|
136
|
+
this.listening = false;
|
|
137
|
+
this.handler = undefined;
|
|
138
|
+
}
|
|
139
|
+
if (closeError) {
|
|
140
|
+
throw closeError;
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
143
|
+
try {
|
|
144
|
+
await this.closePromise;
|
|
117
145
|
} finally {
|
|
118
|
-
this.
|
|
119
|
-
this.listening = false;
|
|
120
|
-
this.handler = undefined;
|
|
121
|
-
}
|
|
122
|
-
if (closeError) {
|
|
123
|
-
throw closeError;
|
|
146
|
+
this.closePromise = undefined;
|
|
124
147
|
}
|
|
125
148
|
}
|
|
126
149
|
async handleIncoming(channel, rawMessage) {
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"grpc",
|
|
14
14
|
"mqtt"
|
|
15
15
|
],
|
|
16
|
-
"version": "1.0.
|
|
16
|
+
"version": "1.0.1",
|
|
17
17
|
"private": false,
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"dist"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@fluojs/
|
|
72
|
-
"@fluojs/
|
|
73
|
-
"@fluojs/runtime": "^1.0.
|
|
71
|
+
"@fluojs/di": "^1.0.1",
|
|
72
|
+
"@fluojs/core": "^1.0.1",
|
|
73
|
+
"@fluojs/runtime": "^1.0.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@grpc/grpc-js": "^1.0.0",
|