Skip to main content
The StreamAdapter trait defines the interface for real-time stream storage and synchronization in the iii framework. Adapters handle CRUD operations, event broadcasting, and WebSocket subscriptions.

Location

Defined in src/modules/stream/adapters/mod.rs

Trait Definition

Required Methods

set

Sets or creates an item in the stream and broadcasts a create/update event.
&str
required
The stream identifier
&str
required
The group/collection within the stream
&str
required
The unique item identifier
Value
required
The item data as a JSON value
anyhow::Result<SetResult>
Result indicating whether item was created or updated

get

Retrieves a single item from the stream.
&str
required
The stream identifier
&str
required
The group/collection within the stream
&str
required
The unique item identifier
anyhow::Result<Option<Value>>
The item data if found, None otherwise

delete

Deletes an item from the stream and broadcasts a delete event.
&str
required
The stream identifier
&str
required
The group/collection within the stream
&str
required
The unique item identifier
anyhow::Result<DeleteResult>
Result indicating success or failure

get_group

Retrieves all items in a group.
&str
required
The stream identifier
&str
required
The group/collection within the stream
anyhow::Result<Vec<Value>>
Vector of all items in the group

list_groups

Lists all group IDs within a stream.
&str
required
The stream identifier
anyhow::Result<Vec<String>>
Vector of group identifiers

list_all_stream

Lists all available streams with their metadata.
anyhow::Result<Vec<StreamMetadata>>
Vector of stream metadata objects

emit_event

Broadcasts an event to all subscribed connections.
StreamWrapperMessage
required
The event message to broadcast
anyhow::Result<()>
Returns Ok(()) on success or an error

subscribe

Registers a WebSocket connection for stream events.
String
required
Unique connection identifier
Arc<dyn StreamConnection>
required
The WebSocket connection handler
anyhow::Result<()>
Returns Ok(()) on success or an error

unsubscribe

Removes a WebSocket connection subscription.
String
required
Connection identifier to remove
anyhow::Result<()>
Returns Ok(()) on success or an error

watch_events

Starts watching for stream events (typically from Redis pub/sub).
anyhow::Result<()>
Returns Ok(()) on success or an error

destroy

Cleans up adapter resources during shutdown.
anyhow::Result<()>
Returns Ok(()) on success or an error

update

Atomically updates an item using JSON operations.
&str
required
The stream identifier
&str
required
The group/collection within the stream
&str
required
The unique item identifier
Vec<UpdateOp>
required
Vector of atomic update operations to apply
anyhow::Result<UpdateResult>
The updated value or an error

Implementation Example

StreamMetadata

Metadata describing a stream and its groups.

StreamWrapperMessage

Wrapper for stream events broadcast to WebSocket connections.

StreamConnection

Trait for WebSocket connection handlers that receive stream events.

UpdateOp

From the iii_sdk crate - represents atomic JSON operations:
  • Set a field
  • Delete a field
  • Append to array
  • Remove from array
  • Increment/decrement numbers

Registration Example

See Also