Configuration
Configure the Stream module inconfig.yaml:
config.yaml
Configuration Options
number
default:"3112"
WebSocket server port
string
default:"127.0.0.1"
Bind address for the WebSocket server
string
Function ID for WebSocket authentication
Available Adapters
- Redis (Recommended)
- KvStore (Development)
Production-ready distributed streams:
Stream Concepts
Streams organize data in a three-level hierarchy:- stream_name: Top-level namespace (e.g., ‘users’, ‘todos’)
- group_id: Collection within stream (e.g., user ID, project ID)
- item_id: Individual item (e.g., document ID)
Stream Functions
Set (Create/Update)
Create or update an item in a stream:Get
Retrieve an item from a stream:Delete
Delete an item from a stream:Update (Atomic)
Atomically update an item with multiple operations:List Items
List all items in a group:List Groups
List all groups in a stream:Send Custom Event
Send a custom event to stream subscribers:Stream Triggers
React to stream events in real-time:index.ts
Event Types
Stream triggers receive events with this format:WebSocket Client (Browser)
Connect to streams from the browser:Authentication
Implement WebSocket authentication:config.yaml
index.ts
Join/Leave Triggers
React to WebSocket connections:Example: Real-time Todo App
index.ts
Performance Tips
- Use Redis adapter for production/distributed systems
- Filter triggers by
group_idoritem_idfor better performance - Use
stream.sendfor lightweight notifications - Implement authentication to prevent unauthorized access
Source Code Reference
- Module:
src/modules/stream/stream.rs:56 - Stream functions:
src/modules/stream/stream.rs:380 - Trigger invocation:
src/modules/stream/stream.rs:249 - WebSocket handler:
src/modules/stream/socket.rs