Changelog - 2026-08-31
EventBus retry and handler reference
New Feature Enhancement Breaking ChangeIn one line. EventBus retries now jitter, each register() call can set its own bounded retry window, and handler replaces handlerBindingKey with a tagged reference that also accepts a plain function.
What changed
- Every retry delay is jittered (
RetryJitterModes.FULL), with no way to turn it off. - Retry timing is per registration.
register()takes an optionalretry: { maxAttempts, baseDelayMs }. Omit it and behavior is unchanged apart from the jitter. - Both retry numbers are bounded.
maxAttemptsis at most 10, and the total backoff window (the sum of every inter-attempt delay, without jitter) is at most 30,000ms. A value over either bound throws atregister(); nothing is clamped silently. For example,maxAttempts: 6withbaseDelayMs: 2000is rejected because its window passes 30 seconds. handlerreplaceshandlerBindingKey. It is a tagged reference: a container binding key, or a plain function.- A handler may return
voidsynchronously, not onlyPromise<void>. A synchronous throw is retried like an asynchronous one.
Who is affected
- Any caller of
EventBus.register(). Wrap the existing binding key as shown below. No other behavior changes for that shape, apart from jitter. - A handler that relied on the fixed retry window. The default window is unchanged, but it is now overridable. Set
retryexplicitly if the timing mattered. IEventHandlerimplementers. Every existingasync handle()still satisfies the interface.
Breaking changes
WARNING
register()'s handlerBindingKey field is removed, not aliased. Update every call site.
Before:
typescript
eventBus.register({
name: 'orderPlaced',
handlerBindingKey: 'services.OrderPlacedHandler',
});After:
typescript
eventBus.register({
name: 'orderPlaced',
handler: { type: EventHandlerTypes.BINDING_KEY, key: 'services.OrderPlacedHandler' },
});A handler with no dependencies can skip the container:
typescript
eventBus.register({
name: 'orderPlaced',
handler: {
type: EventHandlerTypes.FUNCTION,
fn: async ({ event }) => logger.info('Order placed: %s', event.payload.orderId),
},
});Pairing the wrong field with a type (BINDING_KEY with fn, or FUNCTION with key) is a compile error.
Details
BINDING_KEYresolveskeyfrom the container on every retry attempt, so a rebind is picked up by the next attempt.FUNCTIONcapturesfnatregister()time, so every attempt calls the function registered at startup.- Payload maps need
as const. A payload map built from computed keys off a plain object literal (noas const) degrades to an index signature, soregister()andpublish()accept any event name. Nothing reports it. Useas const(or astatic readonlyclass member). To check a map, add a control line; iftscreports the directive as unused, the map has degraded:
typescript
// @ts-expect-error a name nobody declared must not resolve
type Control = IPayloadMap['nothing.declares.this'];