iii-pubsub
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePub/Sub
发布/订阅(Pub/Sub)
iii-pubsubiii-pubsubInstall
安装
bash
iii worker add iii-pubsubbash
iii worker add iii-pubsubCore Model
核心模型
- Producers call with
publish.{ topic, data } - Subscribers register trigger type with
subscribe.{ topic } - Subscriber handlers receive the raw value, not an envelope.
data - Delivery is best-effort broadcast. Use for retries, FIFO, and DLQ.
iii-queue
- 生产者调用 方法,传入参数
publish。{ topic, data } - 订阅者注册类型为 的触发器,配置参数
subscribe。{ topic } - 订阅者处理器接收原始的 值,而非封装信封。
data - 交付采用“尽力而为”的广播方式。如需重试、FIFO排序和死信队列(DLQ)功能,请使用 。
iii-queue
Example
示例
typescript
import { registerWorker, TriggerAction } from 'iii-sdk'
const iii = registerWorker('ws://localhost:49134')
iii.registerFunction('notifications::on-order-shipped', async (data) => {
return { seen: data.orderId }
})
iii.registerTrigger({
type: 'subscribe',
function_id: 'notifications::on-order-shipped',
config: { topic: 'orders.shipped' },
})
await iii.trigger({
function_id: 'publish',
payload: {
topic: 'orders.shipped',
data: { orderId: 'ord_123' },
},
action: TriggerAction.Void(),
})typescript
import { registerWorker, TriggerAction } from 'iii-sdk'
const iii = registerWorker('ws://localhost:49134')
iii.registerFunction('notifications::on-order-shipped', async (data) => {
return { seen: data.orderId }
})
iii.registerTrigger({
type: 'subscribe',
function_id: 'notifications::on-order-shipped',
config: { topic: 'orders.shipped' },
})
await iii.trigger({
function_id: 'publish',
payload: {
topic: 'orders.shipped',
data: { orderId: 'ord_123' },
},
action: TriggerAction.Void(),
})Configuration
配置
yaml
workers:
- name: iii-pubsub
config:
adapter:
name: localUse with when multiple engine instances need to receive the same topic events.
adapter.name: redisredis_urlyaml
workers:
- name: iii-pubsub
config:
adapter:
name: local当多个引擎实例需要接收相同主题事件时,请使用 并配置 。
adapter.name: redisredis_urlPub/Sub vs Queue
发布/订阅(Pub/Sub)与队列对比
| Need | Use |
|---|---|
| Notify every live subscriber now | |
| Retry failed subscribers | |
| Direct async function call with retries | |
| Dead-letter and redrive | |
| Strict ordering | |
| 需求 | 使用工具 |
|---|---|
| 立即通知所有在线订阅者 | |
| 重试失败的订阅者 | |
| 带重试的直接异步函数调用 | |
| 死信处理与重驱动 | |
| 严格排序 | |
When to Use
使用场景
- Use this skill when the task mentions pub/sub, broadcasting, topics, non-durable fanout, live notifications, or fire-and-forget event distribution.
- 当任务涉及发布/订阅、广播、主题、非持久化扇出、实时通知或“即发即弃”事件分发时,请使用此技能。
Boundaries
使用边界
- Do not use pub/sub for guaranteed delivery.
- Do not use when the request explicitly needs non-durable pub/sub.
iii::durable::publish - Do not generate removed service APIs or stream adapter SDK APIs.
- 不要将发布/订阅用于需要保证交付的场景。
- 当请求明确需要非持久化发布/订阅时,请勿使用 。
iii::durable::publish - 请勿生成已移除的服务API或流适配器SDK API。