Example 1
Example 1
import { createApplication } from '@setu-ts/kernel'; import { RuntimePlugin } from '@setu-ts/runtime'; import { RealtimeBackplanePlugin } from '@setu-ts/realtime-backplane-plugin'; import { WebSocketPlugin } from '@setu-ts/websocket-plugin'; const app = createApplication({ plugins: [ RuntimePlugin(), RealtimeBackplanePlugin({ transport: 'redis', url: 'redis://localhost:6379' }), WebSocketPlugin(), ], });
A real single-process backplane.
-
close(): Promise<void>
Closes the underlying transport and drops every handler.
-
connect(): Promise<void>
Opens the underlying transport. Idempotent.
-
handlerErrors(): readonly Error[]
Errors thrown by subscribers during delivery, oldest first.
-
isHealthy(): Promise<boolean>
M70c: a real single-process bus has no backend to be unreachable, so it is always reachable. There is no external dependency whose outage could make this transport
down(M47). -
origin: string
This instance's identity, stamped onto every frame it publishes.
-
publish(frame: RealtimeFrame): Promise<void>
Publishes a frame to every other subscribed instance.
-
subscribe(handler: RealtimeFrameHandler): Promise<() => void>
Registers a handler for frames arriving from other instances.
Carries frames over whatever broker is registered under
CAPABILITIES.MESSAGING.
-
close(): Promise<void>
Closes the underlying transport and drops every handler.
-
connect(): Promise<void>
Opens the underlying transport. Idempotent.
-
handlerErrors(): readonly Error[]
Errors thrown by subscribers during delivery, oldest first.
-
isHealthy: () => Promise<boolean>
M70c: delegates to the resolved broker's
isHealthy?()— the only way the backplane can report the broker's reachability without importing the messaging plugin (§3.1). Assigned only when the broker provides the member: a broker that omits it is unknown, and the indicator reads absence ofisHealthy(notfalse) as that. -
origin: string
This instance's identity, stamped onto every frame it publishes.
-
publish(frame: RealtimeFrame): Promise<void>
Publishes a frame to every other subscribed instance.
-
subscribe(handler: RealtimeFrameHandler): Promise<() => void>
Registers a handler for frames arriving from other instances.
Carries frames over Redis pub/sub.
-
close(): Promise<void>
Closes the underlying transport and drops every handler.
-
connect(): Promise<void>
Builds the client pair when needed, then subscribes.
-
handlerErrors(): readonly Error[]
Errors thrown by subscribers during delivery, oldest first.
-
isHealthy: () => Promise<boolean>
M70c: present only when both connections expose
statusandping; the indicator reads absence as unknown (a minimal fake that lacks the surface has not told us the backend is dead). A subscriber-mode connection refuses every command but (un)subscribe, so the pair is probed separately (M47's two-connection requirement). -
origin: string
This instance's identity, stamped onto every frame it publishes.
-
publish(frame: RealtimeFrame): Promise<void>
Publishes a frame to every other subscribed instance.
-
subscribe(handler: RealtimeFrameHandler): Promise<() => void>
Registers a handler for frames arriving from other instances.
Thrown when ioredis cannot be loaded or does not look like itself.
Narrows an ioredis module to the constructor facade this package uses.
Creates the transport named by options.transport.
Decodes a payload received from the wire back into its local form.
Encodes a WebSocket payload for the wire.
Narrows an arriving broker payload to a RealtimeFrame.
Lazily imports ioredis.
Creates the RealtimeBackplanePlugin.
Options shared by every transport arm.
-
localNotice: boolean
M70n X3-4: when the resolved transport is
'memory', the plugin logs a process-local notice atregister()— frames fan out only within this process, which looks like partial delivery behind more than one replica. Defaulttrue;falsesuppresses the notice, matching the existingscalingNoticeopt-out shape on the SSE and WebSocket plugins. -
origin: string
This instance's identity, stamped on published frames so a subscriber can drop its own echoes. Defaults to a fresh
runtime.uuid(), which is correct for every deployment; override only to make a test deterministic. -
topic: string
The broker topic / Redis channel every instance publishes and subscribes on. Defaults to
'setu-ts.realtime'. Instances must agree on it to see each other.
Options for the 'custom' arm — a caller-supplied transport.
-
instance: IRealtimeBackplane
The transport to register, used as-is.
-
transport: "custom"
Transport discriminant.
A payload as it travels the backplane.
-
binary: boolean
True when
EncodedPayload.datais base64-encoded binary. -
data: string
The payload as a string.
A publish/subscribe transport carrying RealtimeFrames between
application instances.
-
close(): Promise<void>
Closes the underlying transport and drops every handler.
-
connect(): Promise<void>
Opens the underlying transport. Idempotent.
-
isHealthy(): Promise<boolean>
Reports whether the transport's backend is reachable right now, for the plugin's health indicator.
-
origin: string
This instance's identity, stamped onto every frame it publishes.
-
publish(frame: RealtimeFrame): Promise<void>
Publishes a frame to every other subscribed instance.
-
subscribe(handler: RealtimeFrameHandler): Promise<() => void>
Registers a handler for frames arriving from other instances.
The ioredis-shaped client surface the Redis transport uses.
-
off(): voidevent: string,listener: () => voidchannel: string,message: string
Removes a previously registered listener.
-
on(): voidevent: string,listener: () => voidchannel: string,message: string
Registers an event listener. The transport listens for
'message'. -
ping(): Promise<unknown>
M70c: resolves when this connection is alive. Optional so a minimal injected fake still type-checks; the real
ioredisclient exposes it. -
publish(): Promise<number>channel: string,message: string
Publishes a message to a channel.
-
quit(): Promise<unknown>
Closes the connection.
-
status: string
M70c: the
ioredisconnection state ('ready'when usable). Optional for the same reason asping. -
subscribe(channel: string): Promise<unknown>
Subscribes to a channel.
-
unsubscribe(channel: string): Promise<unknown>
Unsubscribes from a channel.
A module exposing an ioredis-compatible constructor.
-
create(url: string): IRedisBackplaneClient
Constructs a client.
Options for the 'memory' arm — a real single-process transport, not a
no-op. Instances sharing one process see each other; separate processes do
not.
-
bus: string
The name of the process-wide bus this instance joins. Two backplanes built with the same name exchange frames; different names are isolated, which is what keeps concurrent tests from bleeding into each other. Defaults to
'default'. -
transport: "memory"
Transport discriminant.
Options for the 'messaging' arm, which carries frames over whatever broker
is registered under CAPABILITIES.MESSAGING.
-
transport: "messaging"
Transport discriminant.
One broadcast crossing the backplane.
-
binary: boolean
True when
RealtimeFrame.datais base64-encoded binary. -
data: string
The payload, always a string.
-
exceptId: string
The connection excluded from this broadcast, by ID.
-
kind: RealtimeFrameKind
Which consumer the frame belongs to.
-
name: string
The room or channel name the frame addresses.
-
origin: string
The publishing instance's identity.
Options for the 'redis' arm — Redis pub/sub.
-
client: IRedisBackplaneClient
The publishing client. Must be supplied together with
RedisBackplaneOptions.subscriber: a Redis connection in subscriber mode refuses every other command, so one connection cannot do both jobs. -
module: IRedisModule
A module exposing an
ioredis-compatible constructor, for testing. -
subscriber: IRedisBackplaneClient
The dedicated subscriber client.
-
transport: "redis"
Transport discriminant.
-
url: string
Connection URL used to build both clients on the lazy
npm:ioredispath. Read only when no clients are injected.
| MessagingBackplaneOptions
| RedisBackplaneOptions
| CustomBackplaneOptions
Options for RealtimeBackplanePlugin, discriminated on
transport.
Receives frames published by other instances.
Which kind of broadcast group a RealtimeFrame addresses.
Standard capability tokens provided by the first-party plugins.
-
AUDIT: string
Audit trail logging.
-
AUTH: string
Authentication service.
-
AUTHORIZATION: string
Authorization service (RBAC, permissions).
-
CACHE: string
Key/value caching.
-
CLI_COMMAND: string
CLI command contributions (multi-provider).
-
CLOUDFLARE: string
Cloudflare Workers platform bindings (KV, R2, D1, Queues, service and Durable Object namespaces) published as one typed accessor.
-
COMMAND_BUS: string
Command bus (CQRS).
-
CONFIG: string
Configuration access.
-
CQRS: string
CQRS facade.
-
DATABASE: string
Database access (repositories, unit of work).
-
DECORATOR_HANDLER: string
Decorator handler contributions (multi-provider).
-
DI_CONTAINER: string
Optional dependency injection container.
-
EVENTS: string
In-memory domain event bus.
-
FEATURE_FLAGS: string
Feature flag evaluation.
-
GRAPHQL: string
GraphQL plugin — schema-first and code-first GraphQL-over-HTTP.
-
GRPC: string
gRPC plugin — server-side Connect/gRPC/gRPC-Web co-serving.
-
HEALTH: string
Health checks.
-
HEALTH_INDICATOR: string
Health indicator contributions (multi-provider).
-
HTTP_ADAPTER: string
HTTP server adapter — the runtime plugin registers its IHttpAdapter here.
-
JWT: string
JWT sign/verify service.
-
LOGGER: string
Structured logger.
-
MAIL: string
Email sending.
-
MESSAGING: string
Message broker for integration events.
-
METADATA_STORE: string
Decorator metadata store (from the DecoratorPlugin, when registered).
-
METRICS: string
Metrics collection.
-
METRIC_REGISTRATION: string
Metric registration contributions (multi-provider).
-
MULTI_TENANCY: string
Multi-tenancy service.
-
NOTIFICATION: string
Multi-channel notifications.
-
OPENAPI: string
OpenAPI spec contribution and generation.
-
OPENAPI_SCHEMA: string
OpenAPI schema contributions (multi-provider).
-
QUERY_BUS: string
Query bus (CQRS).
-
QUEUE: string
Background job queue.
-
REALTIME_BACKPLANE: string
Pub/sub transport carrying real-time broadcasts between application instances, so WebSocket rooms and SSE channels fan out across replicas. Consumed optionally — absent means purely in-process broadcasting.
-
RESILIENCE: string
Resilience patterns (circuit breaker, retry, timeout, bulkhead).
-
RUNTIME: string
Runtime services provided by the RuntimePlugin. Mandatory in every application.
-
SCHEDULER: string
Job scheduling (cron, delayed, recurring).
-
SECRETS: string
Secret management.
-
SERVICE_DISCOVERY: string
Service discovery — logical service name to reachable instances.
-
SESSION: string
Cookie-backed sessions for server-rendered applications.
-
SSE: string
Server-Sent Events (SSE) hub for in-process real-time broadcasting.
-
SSR: string
Server-side rendering (SSR) — React Router or similar framework.
-
STATIC_FILES: string
Static file serving plugin.
-
STORAGE: string
File storage.
-
TELEMETRY: string
Distributed tracing.
-
VALIDATION: string
Request/data validation.
-
VIEW: string
View rendering (server-rendered HTML) — an
IViewEnginethat turns a view component and its props into an HTML string, so a handler can answer with markup it did not concatenate by hand. -
WEBSOCKET: string
WebSocket hub for bidirectional real-time messaging.
-
WORKER_POOL: string
Worker-thread pool for CPU-bound tasks.
The default topic when none is configured.
Usage
import * as __setu_ts_realtime_backplane_plugin____cross_replica_fan_out_for_WebSocket_rooms_and_SSE_channels___The_WebSocket_and_SSE_plugins_hold_their_broadcast_membership_in_ordinary_in_process_sets__correct_and_fast_on_one_instance__invisible_to_every_other__This_plugin_registers_an___linkcode_IRealtimeBackplane__under__CAPABILITIES_REALTIME_BACKPLANE___which_both_of_those_plugins_resolve___optionally_____so_registering_it_is_what_makes__ws_room__lobby____and__sse_channel__news____reach_clients_connected_to_a_different_replica__and_removing_it_returns_them_to_in_process_behavior_with_no_application_change___Three_transports_ship____memory____the_default__a_real_single_process_bus_____messaging____over_whatever_broker_is_registered_under__CAPABILITIES_MESSAGING___reusing_all_five_of_the_messaging_plugin_s_brokers_with_no_new_dependency___and___redis____Redis_pub_sub_over_an_inject_or_lazy__ioredis____A___custom___arm_accepts_any__IRealtimeBackplane____Two_caveats_are_structural_rather_than_incidental___Room_size__and__SseChannel_size__keep_reporting___local___membership__and__RoomBroadcastOptions_except__is_honored_only_on_the_originating_instance__because_it_names_a_live_in_process_connection_with_no_cross_process_identity__ from "realtime-backplane-plugin/src/index.ts";