Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)19k · #10489

iii-stream

Skill này làm gì

Lưu dữ liệu thời gian thực trong các luồng được đặt tên và đẩy các thay đổi tới các client đã kết nối, nên các tính năng trực tiếp không cần polling. Dành cho lập trình viên đang bảo trì hệ thống iii hiện có, vì worker này đã lỗi thời và sẽ bị gỡ.

Khi nào nên dùng

  • ✓Khi bạn đang bảo trì một hệ thống iii hiện có đã dùng luồng.
  • ✓Khi bạn cần một nguồn dữ liệu trực tiếp đẩy cập nhật tới các người đăng ký.
  • ✓Khi bạn định chuyển một tính năng streaming sang một cách tiếp cận mới hơn.

Liên kết skill

https://github.com/iii-hq/iii/blob/main/engine/src/workers/stream/skills/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/iii-hq/iii/blob/main/engine/src/workers/stream/skills/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Cho tôi xem cách một luồng iii hiện có đẩy cập nhật tới các client đã đăng ký, để tôi lên kế hoạch chuyển đổi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Worker lưu các mục trong một cấu trúc ba tầng và gửi mỗi thay đổi tới các client đã đăng ký luồng đó. Một kiểm tra ủy quyền có thể chạy khi client tham gia. Hành vi của nó hiện không đổi, và hướng dẫn chuyển đổi được liên kết từ tài liệu.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

iii-stream

Deprecated. iii-stream is deprecated (iii-stream) and will be removed in an upcoming release. Behavior is unchanged for now. Migration guide: https://iii.dev/docs/upgrading/migrate-from-streams

The iii-stream worker stores real-time data as a three-level hierarchy (stream_name -> group_id -> item_id) in the configured adapter and exposes two surfaces: a CRUD-shaped stream::* function namespace for reading and writing items, and reactive trigger types (stream, stream:join, stream:leave) that fire on data changes and on WebSocket subscriber connect/disconnect. Reactive backends are built by binding handlers to those triggers rather than by polling.

A write persists the new value, dispatches matching stream triggers on a spawned task (fire-and-forget, so the originating call returns before handlers finish), and broadcasts the change to every WebSocket client subscribed to that (stream_name, group_id). The stream:join trigger doubles as an authorization gate: returning { unauthorized: true } from its handler rejects the subscription before any data flows. Pair it with the worker's auth_function config, which runs once per WebSocket handshake and stamps a context value into every join/leave event.

Adapters: kv (default; in-memory or file-backed; single-instance only, no cross-process fan-out) or redis (required for multi-instance fleets that need real-time fan-out). Browser and client subscriptions use the Browser SDK (iii-browser-sdk), which subscribes to stream changes over a single engine WebSocket. Connecting directly to the stream port (ws://host:{port}/stream/{stream_name}/{group_id}) is deprecated in favor of the Browser SDK.

When to Use

  • A stream change should kick off side effects elsewhere (derived projections, audit logs, notifications) without polling stream::list.
  • You need to gate WebSocket subscriptions server-side instead of trusting client-side filtering.
  • You want server-side reactions to subscriber connect/disconnect for presence counters, per-subscription rate buckets, or audit trails.
  • An item needs atomic partial updates that concurrent writers would otherwise race on.

Boundaries

  • Not a general key/value store — data is stream-shaped (stream_name/group_id/item_id). Use the standalone state worker for scope/key values.
  • The default kv adapter does not fan out across processes; multi-instance fleets that need real-time broadcast must use redis.
  • stream:leave is not an authorization gate — the subscription is already gone by the time it fires, and its return value is ignored.
  • Trigger handlers run after the originating write returns; a handler failure neither rolls back the write nor surfaces to the caller.

Functions

  • stream::set — persist an item and broadcast a create/update event; returns the previous value alongside the new one.
  • stream::update — atomically apply ordered set/merge/increment/decrement/append/remove ops to an existing item.
  • stream::delete — remove an item and broadcast a delete event carrying the removed value.
  • stream::send — broadcast a transient event to a group's subscribers without persisting it (typing indicators, cursor positions).
  • stream::get — read one item by its full (stream, group, item) triple.
  • stream::list — enumerate items in a group.
  • stream::list_groups — enumerate groups in a stream.
  • stream::list_all — enumerate every stream's metadata.

Reactive triggers

Bind a stream-family trigger when a function should run automatically on stream activity — without polling stream::list. Three types cover two concerns: stream reacts to data changes, while stream:join / stream:leave react to WebSocket subscriber lifecycle.

Reach for them when:

  • A set/update/delete/send should drive a projection, audit log, or downstream notification.
  • Subscriptions need server-side authorization (stream:join) or paired setup/teardown (stream:join + stream:leave).

If you only need the current value on demand, call stream::get instead of binding a trigger.

How to bind

  1. Register a handler: iii.registerFunction('presence::on-change', handler).
  2. Register the trigger:
iii.registerTrigger({
  type: 'stream',
  function_id: 'presence::on-change',
  config: {
    stream_name: 'presence',  // required for `stream`; the worker indexes triggers by it.
    group_id: 'room-1',       // optional. Empty/omitte
Câu hỏi thường gặp

Worker này còn được hỗ trợ không?

Nó đã lỗi thời và sẽ bị gỡ trong một bản phát hành sắp tới, dù hành vi hiện tại vẫn không đổi.

Hướng dẫn chuyển đổi ở đâu?

Tài liệu của worker liên kết tới một hướng dẫn chuyển đổi trên trang của iii.

Nó có chạy trên nhiều tiến trình máy chủ không?

Chỉ với adapter Redis, vì lưu trữ mặc định không chia sẻ cập nhật giữa các tiến trình.

Chi tiết

Mô tả gốc của tác giả

Durable real-time streams with a CRUD function surface plus reactive triggers that fire on item changes and WebSocket subscriber lifecycle — reach for it to build live backends without polling. iii-stream is deprecated (iii-stream) and will be removed in an upcoming release. Behavior is unchanged for now. Migration guide: https://iii.dev/docs/upgrading/migrate-from-streams

repo: iii-hq/iii

Độ phổ biến

Sao GitHub
19k
Vị trí xếp hạng
#10489
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự