@beignet/provider-event-bus-redis 0.0.38 → 0.0.40
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/CHANGELOG.md +15 -0
- package/README.md +53 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +159 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +189 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @beignet/provider-event-bus-redis
|
|
2
2
|
|
|
3
|
+
## 0.0.40
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3c57a51: Correct provider preset commands and current server setup in package documentation.
|
|
8
|
+
|
|
9
|
+
## 0.0.39
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 019db95: Report Redis publish, connection, and subscription failures consistently,
|
|
14
|
+
retry desired subscriptions after transient command failures, preserve visible
|
|
15
|
+
connection-error fallback logging, isolate rejected error callbacks, and
|
|
16
|
+
document the provider's proven reconnect and deployment semantics.
|
|
17
|
+
|
|
3
18
|
## 0.0.38
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ bun add @beignet/provider-event-bus-redis @beignet/core ioredis
|
|
|
26
26
|
You can also wire it into an existing app with the CLI:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
beignet
|
|
29
|
+
beignet provider add event-bus-redis
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Setup
|
|
@@ -35,6 +35,7 @@ beignet providers add event-bus-redis
|
|
|
35
35
|
import { createNextServer, createNextServerLoader } from "@beignet/next";
|
|
36
36
|
import { createRedisEventBusProvider } from "@beignet/provider-event-bus-redis";
|
|
37
37
|
import { initialPorts } from "@/infra/port-wiring";
|
|
38
|
+
import { appContext } from "@/server/context";
|
|
38
39
|
import { routes } from "@/server/routes";
|
|
39
40
|
|
|
40
41
|
// Set environment variables:
|
|
@@ -45,9 +46,7 @@ export const getServer = createNextServerLoader(() =>
|
|
|
45
46
|
createNextServer({
|
|
46
47
|
ports: initialPorts,
|
|
47
48
|
providers: [createRedisEventBusProvider()],
|
|
48
|
-
context:
|
|
49
|
-
ports,
|
|
50
|
-
}),
|
|
49
|
+
context: appContext,
|
|
51
50
|
routes,
|
|
52
51
|
}),
|
|
53
52
|
);
|
|
@@ -96,7 +95,32 @@ During startup the provider creates separate publisher and subscriber clients,
|
|
|
96
95
|
connects both eagerly, and fails boot with a redacted connection error when
|
|
97
96
|
Redis is unreachable. The default initial connection retry strategy stops
|
|
98
97
|
after `REDIS_EVENT_BUS_CONNECT_MAX_ATTEMPTS`; after a successful connection,
|
|
99
|
-
ioredis reconnects with capped exponential backoff
|
|
98
|
+
ioredis reconnects with capped exponential backoff and resubscribes to the
|
|
99
|
+
channels owned by that subscriber client. Events published while the
|
|
100
|
+
subscriber is disconnected are still lost because Redis Pub/Sub has no replay.
|
|
101
|
+
If an initial `SUBSCRIBE` command fails after ioredis exhausts its command
|
|
102
|
+
retries, the adapter retries that desired subscription with capped backoff for
|
|
103
|
+
as long as at least one local handler remains registered.
|
|
104
|
+
|
|
105
|
+
### Deployment topology
|
|
106
|
+
|
|
107
|
+
The environment-backed provider targets a standalone Redis URL or a managed
|
|
108
|
+
Redis service that exposes one Redis-compatible endpoint. It opens two TCP
|
|
109
|
+
connections per app process: one publisher and one subscriber. Include both in
|
|
110
|
+
the process connection budget.
|
|
111
|
+
|
|
112
|
+
Every long-lived process that should receive events must install the provider
|
|
113
|
+
and register its listeners. Ephemeral request runtimes can publish events, but
|
|
114
|
+
they are not reliable subscriber hosts because Redis only delivers while the
|
|
115
|
+
connection is online. Run subscriptions in a long-lived web or worker process.
|
|
116
|
+
|
|
117
|
+
Sentinel and Redis Cluster require constructor options that cannot be expressed
|
|
118
|
+
by `REDIS_EVENT_BUS_URL`. Apps using those topologies should create their own
|
|
119
|
+
ioredis clients and pass them to `createRedisEventBus(...)`. Beignet's live
|
|
120
|
+
suite does not currently prove Sentinel or Cluster failover semantics, so test
|
|
121
|
+
subscription recovery against the exact managed topology before relying on it.
|
|
122
|
+
HTTP-only Redis APIs are not compatible because Pub/Sub requires a persistent
|
|
123
|
+
Redis connection.
|
|
100
124
|
|
|
101
125
|
## Direct adapter
|
|
102
126
|
|
|
@@ -123,6 +147,8 @@ missed during startup races.
|
|
|
123
147
|
- `publish(...)` publishes one Redis Pub/Sub message on
|
|
124
148
|
`<channelPrefix><event.name>`.
|
|
125
149
|
- Only subscribers that are online and currently subscribed receive the event.
|
|
150
|
+
- ioredis resubscribes after a transient reconnect, but messages published
|
|
151
|
+
during the disconnected interval are not recovered.
|
|
126
152
|
- Payloads are JSON encoded and delivered to handlers without persisting the
|
|
127
153
|
message.
|
|
128
154
|
- When a tracing port is available, the envelope includes Beignet's versioned
|
|
@@ -135,7 +161,17 @@ missed during startup races.
|
|
|
135
161
|
- Invalid messages and subscription errors are reported through
|
|
136
162
|
`onSubscriberError` when provided and recorded as
|
|
137
163
|
`eventBus.message.failed` or `eventBus.subscription.failed` provider
|
|
138
|
-
instrumentation events.
|
|
164
|
+
instrumentation events. Failed subscriptions retry with capped backoff while
|
|
165
|
+
their local handlers remain registered; removing the last handler cancels a
|
|
166
|
+
pending retry.
|
|
167
|
+
- Failed `publish(...)` calls reject with the Redis error and record an
|
|
168
|
+
`eventBus.publish.failed` instrumentation event. The provider does not retry
|
|
169
|
+
the publish after the configured ioredis command retries are exhausted.
|
|
170
|
+
- When the `eventBus` instrumentation watcher is enabled, publisher and
|
|
171
|
+
subscriber connection errors from env-backed clients are recorded as
|
|
172
|
+
`eventBus.connection.failed`. When instrumentation is absent or disabled,
|
|
173
|
+
Beignet leaves ioredis's error fallback intact so connection failures remain
|
|
174
|
+
visible.
|
|
139
175
|
- The provider does not retry handlers, store attempts, replay missed events,
|
|
140
176
|
or dead-letter failures.
|
|
141
177
|
|
|
@@ -156,12 +192,15 @@ ctx.ports.redisEventBus.channelPrefix;
|
|
|
156
192
|
```
|
|
157
193
|
|
|
158
194
|
`checkHealth()` sends cheap `PING` commands to both Redis clients and returns
|
|
159
|
-
metadata suitable for app-owned readiness endpoints.
|
|
195
|
+
metadata suitable for app-owned readiness endpoints. It proves both
|
|
196
|
+
connections can reach Redis; it does not prove that every expected listener
|
|
197
|
+
has registered its channel subscription.
|
|
160
198
|
|
|
161
199
|
## Instrumentation
|
|
162
200
|
|
|
163
|
-
The provider records publish events under the `eventBus` watcher.
|
|
164
|
-
messages
|
|
201
|
+
The provider records successful publish events under the `eventBus` watcher.
|
|
202
|
+
Received messages, failed publishes, connection failures, subscription
|
|
203
|
+
failures, and handler failures are recorded as custom provider events. Payloads
|
|
165
204
|
are not recorded.
|
|
166
205
|
|
|
167
206
|
## Testing
|
|
@@ -172,9 +211,11 @@ the behavior under test specifically depends on cross-process delivery or
|
|
|
172
211
|
Redis connection behavior.
|
|
173
212
|
|
|
174
213
|
This package includes opt-in live Redis integration tests for cross-instance
|
|
175
|
-
delivery,
|
|
176
|
-
|
|
177
|
-
|
|
214
|
+
delivery, reconnect and automatic resubscription, expected loss while offline,
|
|
215
|
+
active-subscription cleanup during shutdown, readiness, instrumentation, and
|
|
216
|
+
failure callbacks. The default `bun run test` command runs the hermetic unit
|
|
217
|
+
suite only so the live tests cannot share process state with the mocked
|
|
218
|
+
`ioredis` tests.
|
|
178
219
|
Set `REDIS_EVENT_BUS_TEST_URL` or the shared `REDIS_TEST_URL` before running
|
|
179
220
|
the dedicated live test command:
|
|
180
221
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAEV,YAAY,EAEb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,uBAAuB,EAG5B,KAAK,6BAA6B,EAClC,K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AAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,kCAAkC;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACjD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AA+ZD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,YAAY,CAEd;AAED,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,kCAAuC,GAC/C,qBAAqB,CAoKvB"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ const DEFAULT_MAX_RETRIES_PER_REQUEST = 2;
|
|
|
13
13
|
const DEFAULT_CONNECT_MAX_ATTEMPTS = 3;
|
|
14
14
|
const DEFAULT_CHANNEL_PREFIX = "beignet:event-bus:";
|
|
15
15
|
const RECONNECT_BACKOFF_CAP_MS = 2000;
|
|
16
|
+
const SUBSCRIPTION_RETRY_BASE_MS = 100;
|
|
17
|
+
const SUBSCRIPTION_RETRY_CAP_MS = 2000;
|
|
16
18
|
const NumberString = z.union([
|
|
17
19
|
z
|
|
18
20
|
.string()
|
|
@@ -50,6 +52,9 @@ function redactConnectionUrl(url) {
|
|
|
50
52
|
function reconnectBackoff(attempt) {
|
|
51
53
|
return Math.min(2 ** attempt * 100, RECONNECT_BACKOFF_CAP_MS);
|
|
52
54
|
}
|
|
55
|
+
function subscriptionRetryBackoff(attempt) {
|
|
56
|
+
return Math.min(SUBSCRIPTION_RETRY_BASE_MS * 2 ** Math.max(0, attempt - 1), SUBSCRIPTION_RETRY_CAP_MS);
|
|
57
|
+
}
|
|
53
58
|
function createRetryStrategy(connectMaxAttempts) {
|
|
54
59
|
let connectedOnce = false;
|
|
55
60
|
return {
|
|
@@ -106,10 +111,13 @@ async function checkRedisEventBusHealth(publisher, subscriber, channelPrefix) {
|
|
|
106
111
|
};
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
|
|
114
|
+
function createRedisEventBusRuntime(options) {
|
|
110
115
|
const channelPrefix = options.channelPrefix ?? DEFAULT_CHANNEL_PREFIX;
|
|
111
116
|
const handlers = new Map();
|
|
112
|
-
const subscribedChannels = new
|
|
117
|
+
const subscribedChannels = new Map();
|
|
118
|
+
const subscriptionRetryAttempts = new Map();
|
|
119
|
+
const subscriptionRetryTimers = new Map();
|
|
120
|
+
let stopped = false;
|
|
113
121
|
const instrumentation = createProviderInstrumentation(options.instrumentation, {
|
|
114
122
|
providerName: "event-bus-redis",
|
|
115
123
|
watcher: "eventBus",
|
|
@@ -129,10 +137,10 @@ export function createRedisEventBus(options) {
|
|
|
129
137
|
},
|
|
130
138
|
});
|
|
131
139
|
try {
|
|
132
|
-
options.onSubscriberError?.(error);
|
|
140
|
+
Promise.resolve(options.onSubscriberError?.(error)).catch(() => undefined);
|
|
133
141
|
}
|
|
134
142
|
catch {
|
|
135
|
-
// Error callbacks should not create
|
|
143
|
+
// Error callbacks should not replace or create another failure.
|
|
136
144
|
}
|
|
137
145
|
};
|
|
138
146
|
const reportHandlerError = (error, eventName, payload) => {
|
|
@@ -146,10 +154,10 @@ export function createRedisEventBus(options) {
|
|
|
146
154
|
},
|
|
147
155
|
});
|
|
148
156
|
try {
|
|
149
|
-
options.onHandlerError?.(error, eventName, payload);
|
|
157
|
+
Promise.resolve(options.onHandlerError?.(error, eventName, payload)).catch(() => undefined);
|
|
150
158
|
}
|
|
151
159
|
catch {
|
|
152
|
-
// Error callbacks should not create
|
|
160
|
+
// Error callbacks should not replace or create another failure.
|
|
153
161
|
}
|
|
154
162
|
};
|
|
155
163
|
const messageHandler = (channel, message) => {
|
|
@@ -198,45 +206,106 @@ export function createRedisEventBus(options) {
|
|
|
198
206
|
}
|
|
199
207
|
};
|
|
200
208
|
options.subscriber.on("message", messageHandler);
|
|
209
|
+
const scheduleSubscriptionRetry = (eventName) => {
|
|
210
|
+
const channel = channelForEvent(channelPrefix, eventName);
|
|
211
|
+
if (stopped ||
|
|
212
|
+
subscriptionRetryTimers.has(channel) ||
|
|
213
|
+
!handlers.get(eventName)?.size) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const retryAttempt = (subscriptionRetryAttempts.get(channel) ?? 0) + 1;
|
|
217
|
+
subscriptionRetryAttempts.set(channel, retryAttempt);
|
|
218
|
+
const timer = setTimeout(() => {
|
|
219
|
+
subscriptionRetryTimers.delete(channel);
|
|
220
|
+
ensureSubscribed(eventName);
|
|
221
|
+
}, subscriptionRetryBackoff(retryAttempt));
|
|
222
|
+
timer.unref?.();
|
|
223
|
+
subscriptionRetryTimers.set(channel, timer);
|
|
224
|
+
};
|
|
201
225
|
const ensureSubscribed = (eventName) => {
|
|
202
226
|
const channel = channelForEvent(channelPrefix, eventName);
|
|
203
|
-
if (
|
|
227
|
+
if (stopped ||
|
|
228
|
+
subscribedChannels.has(channel) ||
|
|
229
|
+
subscriptionRetryTimers.has(channel)) {
|
|
204
230
|
return;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
231
|
+
}
|
|
232
|
+
const attempt = Symbol(channel);
|
|
233
|
+
subscribedChannels.set(channel, attempt);
|
|
234
|
+
const onFailure = (error) => {
|
|
235
|
+
if (subscribedChannels.get(channel) === attempt) {
|
|
236
|
+
subscribedChannels.delete(channel);
|
|
237
|
+
scheduleSubscriptionRetry(eventName);
|
|
238
|
+
}
|
|
208
239
|
reportSubscriberError(error, {
|
|
209
240
|
operation: "subscribe",
|
|
210
241
|
channel,
|
|
211
242
|
eventName,
|
|
212
243
|
});
|
|
213
|
-
}
|
|
244
|
+
};
|
|
245
|
+
try {
|
|
246
|
+
Promise.resolve(options.subscriber.subscribe(channel)).then(() => {
|
|
247
|
+
if (subscribedChannels.get(channel) === attempt) {
|
|
248
|
+
subscriptionRetryAttempts.delete(channel);
|
|
249
|
+
}
|
|
250
|
+
}, onFailure);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
onFailure(error);
|
|
254
|
+
}
|
|
214
255
|
};
|
|
215
256
|
const unsubscribeChannel = (eventName) => {
|
|
216
257
|
const channel = channelForEvent(channelPrefix, eventName);
|
|
217
|
-
|
|
258
|
+
const retryTimer = subscriptionRetryTimers.get(channel);
|
|
259
|
+
if (retryTimer) {
|
|
260
|
+
clearTimeout(retryTimer);
|
|
261
|
+
subscriptionRetryTimers.delete(channel);
|
|
262
|
+
}
|
|
263
|
+
subscriptionRetryAttempts.delete(channel);
|
|
264
|
+
if (!subscribedChannels.has(channel))
|
|
218
265
|
return;
|
|
219
|
-
|
|
266
|
+
subscribedChannels.delete(channel);
|
|
267
|
+
const onFailure = (error) => {
|
|
220
268
|
reportSubscriberError(error, {
|
|
221
269
|
operation: "unsubscribe",
|
|
222
270
|
channel,
|
|
223
271
|
eventName,
|
|
224
272
|
});
|
|
225
|
-
}
|
|
273
|
+
};
|
|
274
|
+
try {
|
|
275
|
+
Promise.resolve(options.subscriber.unsubscribe(channel)).catch(onFailure);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
onFailure(error);
|
|
279
|
+
}
|
|
226
280
|
};
|
|
227
|
-
|
|
281
|
+
const eventBus = {
|
|
228
282
|
async publish(event, payload, publishOptions) {
|
|
229
|
-
instrumentation.record({
|
|
230
|
-
type: "eventBus",
|
|
231
|
-
eventName: event.name,
|
|
232
|
-
});
|
|
233
283
|
const trace = parseTraceCarrier(publishOptions?.trace) ??
|
|
234
284
|
captureTraceCarrier(options.instrumentation);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
285
|
+
try {
|
|
286
|
+
await options.publisher.publish(channelForEvent(channelPrefix, event.name), JSON.stringify({
|
|
287
|
+
eventName: event.name,
|
|
288
|
+
payload,
|
|
289
|
+
...(trace ? { trace } : {}),
|
|
290
|
+
}));
|
|
291
|
+
instrumentation.record({
|
|
292
|
+
type: "eventBus",
|
|
293
|
+
eventName: event.name,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
instrumentation.custom({
|
|
298
|
+
name: "eventBus.publish.failed",
|
|
299
|
+
label: "Event publish failed",
|
|
300
|
+
summary: `Publish failed for "${event.name}"`,
|
|
301
|
+
details: {
|
|
302
|
+
operation: "publish",
|
|
303
|
+
eventName: event.name,
|
|
304
|
+
error: errorMessage(error),
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
240
309
|
},
|
|
241
310
|
subscribe(event, handler) {
|
|
242
311
|
let eventHandlers = handlers.get(event.name);
|
|
@@ -258,6 +327,28 @@ export function createRedisEventBus(options) {
|
|
|
258
327
|
};
|
|
259
328
|
},
|
|
260
329
|
};
|
|
330
|
+
return {
|
|
331
|
+
eventBus,
|
|
332
|
+
stop() {
|
|
333
|
+
stopped = true;
|
|
334
|
+
for (const timer of subscriptionRetryTimers.values()) {
|
|
335
|
+
clearTimeout(timer);
|
|
336
|
+
}
|
|
337
|
+
subscriptionRetryTimers.clear();
|
|
338
|
+
subscriptionRetryAttempts.clear();
|
|
339
|
+
subscribedChannels.clear();
|
|
340
|
+
handlers.clear();
|
|
341
|
+
if (options.subscriber.off) {
|
|
342
|
+
options.subscriber.off("message", messageHandler);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
options.subscriber.removeListener?.("message", messageHandler);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
export function createRedisEventBus(options) {
|
|
351
|
+
return createRedisEventBusRuntime(options).eventBus;
|
|
261
352
|
}
|
|
262
353
|
export function createRedisEventBusProvider(options = {}) {
|
|
263
354
|
const providerMetadata = {
|
|
@@ -316,6 +407,39 @@ export function createRedisEventBusProvider(options = {}) {
|
|
|
316
407
|
...redisOptions,
|
|
317
408
|
retryStrategy: options.retryStrategy ?? subscriberRetry.strategy,
|
|
318
409
|
});
|
|
410
|
+
const connectionInstrumentation = createProviderInstrumentation(ports, {
|
|
411
|
+
providerName: "event-bus-redis",
|
|
412
|
+
watcher: "eventBus",
|
|
413
|
+
});
|
|
414
|
+
const reportPublisherConnectionError = (error) => {
|
|
415
|
+
connectionInstrumentation.custom({
|
|
416
|
+
name: "eventBus.connection.failed",
|
|
417
|
+
label: "Event bus connection failed",
|
|
418
|
+
summary: "Redis event bus publisher connection failed",
|
|
419
|
+
details: {
|
|
420
|
+
operation: "connection",
|
|
421
|
+
role: "publisher",
|
|
422
|
+
error: errorMessage(error),
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
const reportSubscriberConnectionError = (error) => {
|
|
427
|
+
connectionInstrumentation.custom({
|
|
428
|
+
name: "eventBus.connection.failed",
|
|
429
|
+
label: "Event bus connection failed",
|
|
430
|
+
summary: "Redis event bus subscriber connection failed",
|
|
431
|
+
details: {
|
|
432
|
+
operation: "connection",
|
|
433
|
+
role: "subscriber",
|
|
434
|
+
error: errorMessage(error),
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
const observeConnectionErrors = connectionInstrumentation.isEnabled();
|
|
439
|
+
if (observeConnectionErrors) {
|
|
440
|
+
publisher.on("error", reportPublisherConnectionError);
|
|
441
|
+
subscriber.on("error", reportSubscriberConnectionError);
|
|
442
|
+
}
|
|
319
443
|
try {
|
|
320
444
|
await publisher.connect();
|
|
321
445
|
publisherRetry.markConnected();
|
|
@@ -323,16 +447,21 @@ export function createRedisEventBusProvider(options = {}) {
|
|
|
323
447
|
subscriberRetry.markConnected();
|
|
324
448
|
}
|
|
325
449
|
catch (error) {
|
|
450
|
+
if (observeConnectionErrors) {
|
|
451
|
+
publisher.off("error", reportPublisherConnectionError);
|
|
452
|
+
subscriber.off("error", reportSubscriberConnectionError);
|
|
453
|
+
}
|
|
326
454
|
publisher.disconnect();
|
|
327
455
|
subscriber.disconnect();
|
|
328
456
|
throw new Error(`[createRedisEventBusProvider] Failed to connect to Redis at ${redactConnectionUrl(config.URL)}: ${errorMessage(error)}`);
|
|
329
457
|
}
|
|
330
|
-
const
|
|
458
|
+
const eventBusRuntime = createRedisEventBusRuntime({
|
|
331
459
|
publisher,
|
|
332
460
|
subscriber,
|
|
333
461
|
channelPrefix: configuredChannelPrefix,
|
|
334
462
|
instrumentation: ports,
|
|
335
463
|
});
|
|
464
|
+
const eventBus = eventBusRuntime.eventBus;
|
|
336
465
|
return {
|
|
337
466
|
ports: {
|
|
338
467
|
eventBus,
|
|
@@ -344,6 +473,7 @@ export function createRedisEventBusProvider(options = {}) {
|
|
|
344
473
|
},
|
|
345
474
|
},
|
|
346
475
|
async stop() {
|
|
476
|
+
eventBusRuntime.stop();
|
|
347
477
|
try {
|
|
348
478
|
await subscriber.quit();
|
|
349
479
|
}
|
|
@@ -356,6 +486,10 @@ export function createRedisEventBusProvider(options = {}) {
|
|
|
356
486
|
catch {
|
|
357
487
|
publisher.disconnect();
|
|
358
488
|
}
|
|
489
|
+
if (observeConnectionErrors) {
|
|
490
|
+
publisher.off("error", reportPublisherConnectionError);
|
|
491
|
+
subscriber.off("error", reportSubscriberConnectionError);
|
|
492
|
+
}
|
|
359
493
|
},
|
|
360
494
|
};
|
|
361
495
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAEL,cAAc,EACd,6BAA6B,GAG9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,+BAA+B,GAAG,CA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,CAChB,wBAAwB,CACtB,SAAS,EACT,UAAU,EACV,uBAAuB,CACxB;qBACJ;iBACmC;gBACtC,KAAK,CAAC,IAAI;oBACR,eAAe,CAAC,IAAI,EAAE,CAAC;oBACvB,IAAI,CAAC;wBACH,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;oBAC1B,CAAC;oBAAC,MAAM,CAAC;wBACP,UAAU,CAAC,UAAU,EAAE,CAAC;oBAC1B,CAAC;oBACD,IAAI,CAAC;wBACH,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;oBACzB,CAAC;oBAAC,MAAM,CAAC;wBACP,SAAS,CAAC,UAAU,EAAE,CAAC;oBACzB,CAAC;oBACD,IAAI,uBAAuB,EAAE,CAAC;wBAC5B,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;wBACvD,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,+BAA+B,CAAC,CAAC;oBAC3D,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beignet/provider-event-bus-redis",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Redis Pub/Sub event bus provider for Beignet - implements EventBusPort for cross-process best-effort delivery",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,8 @@ const DEFAULT_MAX_RETRIES_PER_REQUEST = 2;
|
|
|
30
30
|
const DEFAULT_CONNECT_MAX_ATTEMPTS = 3;
|
|
31
31
|
const DEFAULT_CHANNEL_PREFIX = "beignet:event-bus:";
|
|
32
32
|
const RECONNECT_BACKOFF_CAP_MS = 2000;
|
|
33
|
+
const SUBSCRIPTION_RETRY_BASE_MS = 100;
|
|
34
|
+
const SUBSCRIPTION_RETRY_CAP_MS = 2000;
|
|
33
35
|
|
|
34
36
|
const NumberString = z.union([
|
|
35
37
|
z
|
|
@@ -159,6 +161,13 @@ function reconnectBackoff(attempt: number): number {
|
|
|
159
161
|
return Math.min(2 ** attempt * 100, RECONNECT_BACKOFF_CAP_MS);
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
function subscriptionRetryBackoff(attempt: number): number {
|
|
165
|
+
return Math.min(
|
|
166
|
+
SUBSCRIPTION_RETRY_BASE_MS * 2 ** Math.max(0, attempt - 1),
|
|
167
|
+
SUBSCRIPTION_RETRY_CAP_MS,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
162
171
|
function createRetryStrategy(connectMaxAttempts: number): {
|
|
163
172
|
strategy: (attempt: number) => number | null;
|
|
164
173
|
markConnected: () => void;
|
|
@@ -229,9 +238,14 @@ async function checkRedisEventBusHealth(
|
|
|
229
238
|
}
|
|
230
239
|
}
|
|
231
240
|
|
|
232
|
-
|
|
241
|
+
interface RedisEventBusRuntime {
|
|
242
|
+
eventBus: EventBusPort;
|
|
243
|
+
stop(): void;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function createRedisEventBusRuntime(
|
|
233
247
|
options: CreateRedisEventBusOptions,
|
|
234
|
-
):
|
|
248
|
+
): RedisEventBusRuntime {
|
|
235
249
|
const channelPrefix = options.channelPrefix ?? DEFAULT_CHANNEL_PREFIX;
|
|
236
250
|
const handlers = new Map<
|
|
237
251
|
string,
|
|
@@ -242,7 +256,13 @@ export function createRedisEventBus(
|
|
|
242
256
|
) => void | Promise<void>
|
|
243
257
|
>
|
|
244
258
|
>();
|
|
245
|
-
const subscribedChannels = new
|
|
259
|
+
const subscribedChannels = new Map<string, symbol>();
|
|
260
|
+
const subscriptionRetryAttempts = new Map<string, number>();
|
|
261
|
+
const subscriptionRetryTimers = new Map<
|
|
262
|
+
string,
|
|
263
|
+
ReturnType<typeof setTimeout>
|
|
264
|
+
>();
|
|
265
|
+
let stopped = false;
|
|
246
266
|
const instrumentation = createProviderInstrumentation(
|
|
247
267
|
options.instrumentation,
|
|
248
268
|
{
|
|
@@ -277,9 +297,11 @@ export function createRedisEventBus(
|
|
|
277
297
|
});
|
|
278
298
|
|
|
279
299
|
try {
|
|
280
|
-
options.onSubscriberError?.(error)
|
|
300
|
+
Promise.resolve(options.onSubscriberError?.(error)).catch(
|
|
301
|
+
() => undefined,
|
|
302
|
+
);
|
|
281
303
|
} catch {
|
|
282
|
-
// Error callbacks should not create
|
|
304
|
+
// Error callbacks should not replace or create another failure.
|
|
283
305
|
}
|
|
284
306
|
};
|
|
285
307
|
|
|
@@ -299,9 +321,11 @@ export function createRedisEventBus(
|
|
|
299
321
|
});
|
|
300
322
|
|
|
301
323
|
try {
|
|
302
|
-
|
|
324
|
+
Promise.resolve(
|
|
325
|
+
options.onHandlerError?.(error, eventName, payload),
|
|
326
|
+
).catch(() => undefined);
|
|
303
327
|
} catch {
|
|
304
|
-
// Error callbacks should not create
|
|
328
|
+
// Error callbacks should not replace or create another failure.
|
|
305
329
|
}
|
|
306
330
|
};
|
|
307
331
|
|
|
@@ -357,50 +381,118 @@ export function createRedisEventBus(
|
|
|
357
381
|
|
|
358
382
|
options.subscriber.on("message", messageHandler);
|
|
359
383
|
|
|
384
|
+
const scheduleSubscriptionRetry = (eventName: string) => {
|
|
385
|
+
const channel = channelForEvent(channelPrefix, eventName);
|
|
386
|
+
if (
|
|
387
|
+
stopped ||
|
|
388
|
+
subscriptionRetryTimers.has(channel) ||
|
|
389
|
+
!handlers.get(eventName)?.size
|
|
390
|
+
) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const retryAttempt = (subscriptionRetryAttempts.get(channel) ?? 0) + 1;
|
|
395
|
+
subscriptionRetryAttempts.set(channel, retryAttempt);
|
|
396
|
+
const timer = setTimeout(() => {
|
|
397
|
+
subscriptionRetryTimers.delete(channel);
|
|
398
|
+
ensureSubscribed(eventName);
|
|
399
|
+
}, subscriptionRetryBackoff(retryAttempt));
|
|
400
|
+
timer.unref?.();
|
|
401
|
+
subscriptionRetryTimers.set(channel, timer);
|
|
402
|
+
};
|
|
403
|
+
|
|
360
404
|
const ensureSubscribed = (eventName: string) => {
|
|
361
405
|
const channel = channelForEvent(channelPrefix, eventName);
|
|
362
|
-
if (
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
406
|
+
if (
|
|
407
|
+
stopped ||
|
|
408
|
+
subscribedChannels.has(channel) ||
|
|
409
|
+
subscriptionRetryTimers.has(channel)
|
|
410
|
+
) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const attempt = Symbol(channel);
|
|
414
|
+
subscribedChannels.set(channel, attempt);
|
|
415
|
+
|
|
416
|
+
const onFailure = (error: unknown) => {
|
|
417
|
+
if (subscribedChannels.get(channel) === attempt) {
|
|
418
|
+
subscribedChannels.delete(channel);
|
|
419
|
+
scheduleSubscriptionRetry(eventName);
|
|
420
|
+
}
|
|
366
421
|
reportSubscriberError(error, {
|
|
367
422
|
operation: "subscribe",
|
|
368
423
|
channel,
|
|
369
424
|
eventName,
|
|
370
425
|
});
|
|
371
|
-
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
try {
|
|
429
|
+
Promise.resolve(options.subscriber.subscribe(channel)).then(() => {
|
|
430
|
+
if (subscribedChannels.get(channel) === attempt) {
|
|
431
|
+
subscriptionRetryAttempts.delete(channel);
|
|
432
|
+
}
|
|
433
|
+
}, onFailure);
|
|
434
|
+
} catch (error) {
|
|
435
|
+
onFailure(error);
|
|
436
|
+
}
|
|
372
437
|
};
|
|
373
438
|
|
|
374
439
|
const unsubscribeChannel = (eventName: string) => {
|
|
375
440
|
const channel = channelForEvent(channelPrefix, eventName);
|
|
376
|
-
|
|
377
|
-
|
|
441
|
+
const retryTimer = subscriptionRetryTimers.get(channel);
|
|
442
|
+
if (retryTimer) {
|
|
443
|
+
clearTimeout(retryTimer);
|
|
444
|
+
subscriptionRetryTimers.delete(channel);
|
|
445
|
+
}
|
|
446
|
+
subscriptionRetryAttempts.delete(channel);
|
|
447
|
+
if (!subscribedChannels.has(channel)) return;
|
|
448
|
+
subscribedChannels.delete(channel);
|
|
449
|
+
|
|
450
|
+
const onFailure = (error: unknown) => {
|
|
378
451
|
reportSubscriberError(error, {
|
|
379
452
|
operation: "unsubscribe",
|
|
380
453
|
channel,
|
|
381
454
|
eventName,
|
|
382
455
|
});
|
|
383
|
-
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
Promise.resolve(options.subscriber.unsubscribe(channel)).catch(onFailure);
|
|
460
|
+
} catch (error) {
|
|
461
|
+
onFailure(error);
|
|
462
|
+
}
|
|
384
463
|
};
|
|
385
464
|
|
|
386
|
-
|
|
465
|
+
const eventBus: EventBusPort = {
|
|
387
466
|
async publish(event, payload, publishOptions) {
|
|
388
|
-
instrumentation.record({
|
|
389
|
-
type: "eventBus",
|
|
390
|
-
eventName: event.name,
|
|
391
|
-
});
|
|
392
|
-
|
|
393
467
|
const trace =
|
|
394
468
|
parseTraceCarrier(publishOptions?.trace) ??
|
|
395
469
|
captureTraceCarrier(options.instrumentation);
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
470
|
+
try {
|
|
471
|
+
await options.publisher.publish(
|
|
472
|
+
channelForEvent(channelPrefix, event.name),
|
|
473
|
+
JSON.stringify({
|
|
474
|
+
eventName: event.name,
|
|
475
|
+
payload,
|
|
476
|
+
...(trace ? { trace } : {}),
|
|
477
|
+
}),
|
|
478
|
+
);
|
|
479
|
+
instrumentation.record({
|
|
480
|
+
type: "eventBus",
|
|
399
481
|
eventName: event.name,
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
482
|
+
});
|
|
483
|
+
} catch (error) {
|
|
484
|
+
instrumentation.custom({
|
|
485
|
+
name: "eventBus.publish.failed",
|
|
486
|
+
label: "Event publish failed",
|
|
487
|
+
summary: `Publish failed for "${event.name}"`,
|
|
488
|
+
details: {
|
|
489
|
+
operation: "publish",
|
|
490
|
+
eventName: event.name,
|
|
491
|
+
error: errorMessage(error),
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
throw error;
|
|
495
|
+
}
|
|
404
496
|
},
|
|
405
497
|
|
|
406
498
|
subscribe<E extends DomainEventDef>(
|
|
@@ -440,6 +532,31 @@ export function createRedisEventBus(
|
|
|
440
532
|
};
|
|
441
533
|
},
|
|
442
534
|
};
|
|
535
|
+
|
|
536
|
+
return {
|
|
537
|
+
eventBus,
|
|
538
|
+
stop() {
|
|
539
|
+
stopped = true;
|
|
540
|
+
for (const timer of subscriptionRetryTimers.values()) {
|
|
541
|
+
clearTimeout(timer);
|
|
542
|
+
}
|
|
543
|
+
subscriptionRetryTimers.clear();
|
|
544
|
+
subscriptionRetryAttempts.clear();
|
|
545
|
+
subscribedChannels.clear();
|
|
546
|
+
handlers.clear();
|
|
547
|
+
if (options.subscriber.off) {
|
|
548
|
+
options.subscriber.off("message", messageHandler);
|
|
549
|
+
} else {
|
|
550
|
+
options.subscriber.removeListener?.("message", messageHandler);
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function createRedisEventBus(
|
|
557
|
+
options: CreateRedisEventBusOptions,
|
|
558
|
+
): EventBusPort {
|
|
559
|
+
return createRedisEventBusRuntime(options).eventBus;
|
|
443
560
|
}
|
|
444
561
|
|
|
445
562
|
export function createRedisEventBusProvider(
|
|
@@ -512,6 +629,39 @@ export function createRedisEventBusProvider(
|
|
|
512
629
|
...redisOptions,
|
|
513
630
|
retryStrategy: options.retryStrategy ?? subscriberRetry.strategy,
|
|
514
631
|
});
|
|
632
|
+
const connectionInstrumentation = createProviderInstrumentation(ports, {
|
|
633
|
+
providerName: "event-bus-redis",
|
|
634
|
+
watcher: "eventBus",
|
|
635
|
+
});
|
|
636
|
+
const reportPublisherConnectionError = (error: unknown) => {
|
|
637
|
+
connectionInstrumentation.custom({
|
|
638
|
+
name: "eventBus.connection.failed",
|
|
639
|
+
label: "Event bus connection failed",
|
|
640
|
+
summary: "Redis event bus publisher connection failed",
|
|
641
|
+
details: {
|
|
642
|
+
operation: "connection",
|
|
643
|
+
role: "publisher",
|
|
644
|
+
error: errorMessage(error),
|
|
645
|
+
},
|
|
646
|
+
});
|
|
647
|
+
};
|
|
648
|
+
const reportSubscriberConnectionError = (error: unknown) => {
|
|
649
|
+
connectionInstrumentation.custom({
|
|
650
|
+
name: "eventBus.connection.failed",
|
|
651
|
+
label: "Event bus connection failed",
|
|
652
|
+
summary: "Redis event bus subscriber connection failed",
|
|
653
|
+
details: {
|
|
654
|
+
operation: "connection",
|
|
655
|
+
role: "subscriber",
|
|
656
|
+
error: errorMessage(error),
|
|
657
|
+
},
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
const observeConnectionErrors = connectionInstrumentation.isEnabled();
|
|
661
|
+
if (observeConnectionErrors) {
|
|
662
|
+
publisher.on("error", reportPublisherConnectionError);
|
|
663
|
+
subscriber.on("error", reportSubscriberConnectionError);
|
|
664
|
+
}
|
|
515
665
|
|
|
516
666
|
try {
|
|
517
667
|
await publisher.connect();
|
|
@@ -519,6 +669,10 @@ export function createRedisEventBusProvider(
|
|
|
519
669
|
await subscriber.connect();
|
|
520
670
|
subscriberRetry.markConnected();
|
|
521
671
|
} catch (error) {
|
|
672
|
+
if (observeConnectionErrors) {
|
|
673
|
+
publisher.off("error", reportPublisherConnectionError);
|
|
674
|
+
subscriber.off("error", reportSubscriberConnectionError);
|
|
675
|
+
}
|
|
522
676
|
publisher.disconnect();
|
|
523
677
|
subscriber.disconnect();
|
|
524
678
|
throw new Error(
|
|
@@ -528,12 +682,13 @@ export function createRedisEventBusProvider(
|
|
|
528
682
|
);
|
|
529
683
|
}
|
|
530
684
|
|
|
531
|
-
const
|
|
685
|
+
const eventBusRuntime = createRedisEventBusRuntime({
|
|
532
686
|
publisher,
|
|
533
687
|
subscriber,
|
|
534
688
|
channelPrefix: configuredChannelPrefix,
|
|
535
689
|
instrumentation: ports,
|
|
536
690
|
});
|
|
691
|
+
const eventBus = eventBusRuntime.eventBus;
|
|
537
692
|
|
|
538
693
|
return {
|
|
539
694
|
ports: {
|
|
@@ -551,6 +706,7 @@ export function createRedisEventBusProvider(
|
|
|
551
706
|
},
|
|
552
707
|
} satisfies RedisEventBusProviderPorts,
|
|
553
708
|
async stop() {
|
|
709
|
+
eventBusRuntime.stop();
|
|
554
710
|
try {
|
|
555
711
|
await subscriber.quit();
|
|
556
712
|
} catch {
|
|
@@ -561,6 +717,10 @@ export function createRedisEventBusProvider(
|
|
|
561
717
|
} catch {
|
|
562
718
|
publisher.disconnect();
|
|
563
719
|
}
|
|
720
|
+
if (observeConnectionErrors) {
|
|
721
|
+
publisher.off("error", reportPublisherConnectionError);
|
|
722
|
+
subscriber.off("error", reportSubscriberConnectionError);
|
|
723
|
+
}
|
|
564
724
|
},
|
|
565
725
|
};
|
|
566
726
|
},
|