Skip to main content

Module realtime

Module realtime 

Source
Expand description

Real-time protocol engine: WebSocket gateways + Server-Sent Events.

NestJS-Gateway ergonomics on a zero-cost, lock-free-on-the-hot-path Rust core. Declare a gateway, subscribe to events, broadcast to rooms — without ever naming an axum/tower type.

#[Injectable]
pub struct ChatGateway { db: Inject<Db> }

impl ArclyGateway for ChatGateway {
    async fn on_connect(&self, client: WsClient) { client.join_room("lobby"); }
}

#[Gateway("/chat-socket")]
impl ChatGateway {
    #[Subscribe("message::send")]
    async fn on_message(&self, client: WsClient, payload: Json<ChatMessage>)
        -> Result<(), Error>
    {
        client.broadcast_to_room(&payload.room, "message::receive", &*payload).await;
        Ok(())
    }
}

See macros for the exact expansion contract and the rationale for the #[Gateway]-on-impl placement.

Modules§

connection
Lock-free connection & broadcasting registry.
gateway
Gateway contracts: the ArclyGateway lifecycle trait and the link-time descriptor / runtime types the #[Gateway] macro emits.
macros
Registry glue for the real-time macro layer.
sse
High-performance Server-Sent Events engine.
ws
WebSocket boundary: upgrade, per-socket read/write pumps, event dispatch.

Structs§

ConnectionRegistry
Sharded, lock-free-on-the-hot-path connection registry.
GatewayDescriptor
Link-time gateway registration. One is emitted per #[Gateway] impl and collected via inventory. build constructs the gateway (wiring its Inject<T> fields from the frozen container) and assembles the runtime.
GatewayRuntime
The fully-constructed, ready-to-serve form of a gateway. Produced once at launch by GatewayDescriptor::build and leaked to &'static.
SseEvent
A single Server-Sent Event. Builder-style; all fields optional except data.
SseStream
A streaming text/event-stream response body.
WsClient
A cheap, clonable handle to one connected client.

Enums§

WsMessage
An arcly-owned outbound frame. The websocket boundary maps this onto the concrete transport frame type — keeping axum out of the public surface.

Traits§

ArclyGateway
Connection lifecycle for a real-time gateway.

Functions§

ws_route
Build the axum MethodRouter that upgrades HTTP→WebSocket for one gateway.

Type Aliases§

ConnId
Monotonic, process-unique connection identifier.
LifecycleHook
A type-erased lifecycle hook closure (built by the macro over a concrete gateway instance).
MessageHandler
A type-erased event handler. Receives the originating client and the raw JSON data payload (as borrowed text), returns the handler’s Result.

Attribute Macros§

Gateway
#[Gateway("/path")] — declare a WebSocket gateway.
Subscribe
#[Subscribe("event::name")] — marker consumed by the enclosing #[Gateway] walker. Pass-through so it also type-checks if a tool resolves it directly.