PubSubHub
Thread-safe in-memory pub/sub router scoped to a Flet server process.
Subscribers are grouped by session ID and optionally by topic. Handlers can
be synchronous callables or async coroutine functions:
- global subscribers receive (message);
- topic subscribers receive (topic, message).
This hub is used by session-scoped PubSubClient
instances to fan out messages between connected sessions.
Methods
-
send_all–Sends a message to all global subscribers across all sessions.
-
send_all_on_topic–Sends a topic message to all subscribers of
topic. -
send_others–Sends a global message to all sessions except one.
-
send_others_on_topic–Sends a topic message to all subscribers except one session.
-
subscribe–Registers a global subscriber for a session.
-
subscribe_topic–Registers a topic subscriber for a session.
-
unsubscribe–Removes all global subscribers for a session.
-
unsubscribe_all–Removes both global and topic subscriptions for a session.
-
unsubscribe_topic–Removes all handlers for a specific session/topic pair.
Methods#
send_all
#
send_all(message: Any)
Sends a message to all global subscribers across all sessions.
Parameters:
-
message(Any) –Payload to deliver.
send_all_on_topic
#
send_others
#
send_others_on_topic
#
subscribe
#
Registers a global subscriber for a session.
The handler will receive one positional argument: message.
Duplicate registrations of the same handler are ignored because
handlers are stored in a set.
Parameters:
subscribe_topic
#
Registers a topic subscriber for a session.
The handler will receive two positional arguments: (topic, message).
Parameters:
unsubscribe
#
unsubscribe(session_id: str)
Removes all global subscribers for a session.
This does not remove topic subscriptions; use
unsubscribe_all() to remove both.
Parameters:
-
session_id(str) –Session identifier to remove.