PubSubClient
Session-scoped facade over PubSubHub.
This client binds all pub/sub operations to one session ID so callers can publish and subscribe without passing their session identity explicitly on each call.
Methods
send_all- Broadcasts a global message to all sessions.send_all_on_topic- Broadcasts a topic message to all subscribers oftopic.send_others- Broadcasts a global message to all sessions except this client session.send_others_on_topic- Broadcasts a topic message excluding this client session.subscribe- Subscribes this session to global messages.subscribe_topic- Subscribes this session to a topic.unsubscribe- Removes global subscriptions for this session.unsubscribe_all- Removes all global and topic subscriptions for this session.unsubscribe_topic- Removes this session's subscriptions for a specific topic.
Methods
send_all
send_all(message: Any)Broadcasts a global message to all sessions.
Parameters:
- message (Any) - Payload to publish.
send_all_on_topic
send_all_on_topic(topic: str, message: Any)Broadcasts a topic message to all subscribers of topic.
Parameters:
- topic (str) - Topic name to publish on.
- message (Any) - Payload to publish.
send_others
send_others(message: Any)Broadcasts a global message to all sessions except this client session.
Parameters:
- message (Any) - Payload to publish.
send_others_on_topic
send_others_on_topic(topic: str, message: Any)Broadcasts a topic message excluding this client session.
Parameters:
- topic (str) - Topic name to publish on.
- message (Any) - Payload to publish.
subscribe
subscribe(handler: Callable)Subscribes this session to global messages.
The handler is invoked with one positional argument: message.
Parameters:
- handler (Callable) - Sync or async callback for global messages.
subscribe_topic
subscribe_topic(topic: str, handler: Callable)Subscribes this session to a topic.
The handler is invoked with two positional arguments:
(topic, message).
Parameters:
- topic (str) - Topic name to subscribe to.
- handler (Callable) - Sync or async callback for topic messages.
unsubscribe_topic
unsubscribe_topic(topic: str)Removes this session's subscriptions for a specific topic.
Parameters:
- topic (str) - Topic to unsubscribe from.