Skip to main content
The Stream module provides real-time WebSocket connections for bidirectional communication and reactive data streams. Perfect for live updates, chat applications, and collaborative features.

Configuration

Configure the Stream module in config.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

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)
Example:

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
Auth function:
index.ts
Access auth context in triggers:

Join/Leave Triggers

React to WebSocket connections:

Example: Real-time Todo App

index.ts
Browser client:

Performance Tips

  • Use Redis adapter for production/distributed systems
  • Filter triggers by group_id or item_id for better performance
  • Use stream.send for 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