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
ArclyGatewaylifecycle 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§
- Connection
Registry - Sharded, lock-free-on-the-hot-path connection registry.
- Gateway
Descriptor - Link-time gateway registration. One is emitted per
#[Gateway]impl and collected viainventory.buildconstructs the gateway (wiring itsInject<T>fields from the frozen container) and assembles the runtime. - Gateway
Runtime - The fully-constructed, ready-to-serve form of a gateway. Produced once at
launch by
GatewayDescriptor::buildand leaked to&'static. - SseEvent
- A single Server-Sent Event. Builder-style; all fields optional except data.
- SseStream
- A streaming
text/event-streamresponse 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
axumout of the public surface.
Traits§
- Arcly
Gateway - Connection lifecycle for a real-time gateway.
Functions§
- ws_
route - Build the axum
MethodRouterthat upgrades HTTP→WebSocket for one gateway.
Type Aliases§
- ConnId
- Monotonic, process-unique connection identifier.
- Lifecycle
Hook - A type-erased lifecycle hook closure (built by the macro over a concrete gateway instance).
- Message
Handler - A type-erased event handler. Receives the originating client and the raw
JSON
datapayload (as borrowed text), returns the handler’sResult.