主题
PubSubClient
基于 PubSubHub 的会话级门面(facade)。
该客户端将所有发布/订阅(pub/sub)操作绑定到同一个会话 ID,调用方因此无需在每次调用时显式传入自己的会话标识,即可发布和订阅消息。
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
send_all | — | — | Broadcasts a global message to all sessions. Args: message: Payload to publish. |
send_all_on_topic | — | — | Broadcasts a topic message to all subscribers of topic. Args: topic: Topic name to publish on. message: Payload to publish. |
send_others | — | — | Broadcasts a global message to all sessions except this client session. Args: message: Payload to publish. |
send_others_on_topic | — | — | Broadcasts a topic message excluding this client session. Args: topic: Topic name to publish on. message: Payload to publish. |
subscribe | — | — | Subscribes this session to global messages. The handler is invoked with one positional argument: message. Args: handler: Sync or async callback for global messages. |
subscribe_topic | — | — | Subscribes this session to a topic. The handler is invoked with two positional arguments: (topic, message). Args: topic: Topic name to subscribe to. handler: Sync or async callback for topic messages. |
unsubscribe | — | — | Removes global subscriptions for this session. |
unsubscribe_topic | — | — | Removes this session's subscriptions for a specific topic. Args: topic: Topic to unsubscribe from. |
unsubscribe_all | — | — | Removes all global and topic subscriptions for this session. |