Skip to content

Hello NestForge WebSockets

What the WebSocket-first example includes and how it combines gateway behavior with microservice patterns.

Example location:

examples/hello-nestforge-websockets

Run it from the repository root:

Terminal window
cargo run -p hello-nestforge-websockets

The gateway listens on ws://127.0.0.1:3002/ws.

This example shows a gateway-first application that uses NestForge’s WebSocket support while keeping provider resolution and config loading inside the framework module model.

The example currently includes:

  • src/main.rs
  • src/app_module.rs
  • src/app_config.rs
  • src/ws/mod.rs
  • src/ws/events_gateway.rs
  • src/ws/patterns.rs

Read the example in this order:

  1. src/app_module.rs
  2. src/ws/patterns.rs
  3. src/ws/events_gateway.rs
  4. src/main.rs

Bootstraps an HTTP server and mounts a WebSocket gateway on the default /ws route. It listens on port 3002.

Registers and exports the app config plus a WsPatterns registry provider.

Defines the EventsGateway that:

  • sends an initial connection message
  • resolves AppConfig
  • optionally resolves WsPatterns
  • loops over incoming frames
  • delegates supported frames to handle_websocket_microservice_message(...)

Defines transport-neutral patterns such as:

  • app.info
  • app.ping
  • how gateways receive WebSocketContext
  • how to resolve providers from the gateway
  • how to mix direct WebSocket behavior with microservice-pattern dispatch
  • how to expose a lightweight event-driven interface without a full broker

When you connect to the socket, verify:

  1. the connection message is sent
  2. AppConfig resolves inside the gateway
  3. JSON frames can be forwarded into WsPatterns
  4. responses or errors are sent back to the socket