Back to Rivet

Chat Room (Rust)

examples/chat-room-rust/README.md

2.3.21.4 KB
Original Source

Chat Room (Rust)

Example project demonstrating real-time messaging and actor state management in Rust. This is the Rust translation of the chat-room example.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/chat-room-rust
cargo build -p rivet-engine
RIVET_ENGINE_BINARY_PATH=../../target/debug/rivet-engine cargo run

See the Rust Quickstart for creating the actor and connecting clients.

Features

  • Real-time messaging: Broadcast messages to all connected clients instantly
  • Persistent chat history: Messages stored in actor SQLite across restarts
  • Persistent actor state: A framework-managed State value tracks message stats
  • Multiple chat rooms: Each room key is a separate actor instance with isolated state
  • Event-driven architecture: Use actor events to push updates to clients in real-time

Implementation

The chat room demonstrates core Rivet Actor patterns for real-time communication:

  • Actor Definition (src/lib.rs): Defines the chatRoom actor with SQLite-backed message history, persisted stats, sendMessage / getHistory / getStats actions, and a newMessage event

Resources

Read more about actions, state, and events.

License

MIT