Events
Events are pushed to the client through a publish-subscribe mechanism through all the protocols. Call the push() method on the event to publish data to clients:
Subscription
One can subscribe to the event using the attribute name:
In the default synchronous mode, the subscribe_event method spawns a thread that listens to the event in the background:
In the asynchronous mode, the subscribe_event method creates an event listening task in the running async loop. This requires the client to be running in an async loop, otherwise no events will be received although the server will be publishing them:
The callback function(s) must accept a single argument - an instance of the SSE object. The payload can be accessed using the data attribute:
The
SSEobject also contains metadata likeid,eventname andretryinterval, but these are currently not well supported. Improvements in the future are expected.
Each subscription creates a new event stream. One can also supply multiple callbacks which may be called in series or concurrently:
The background thread that listens to the event executes the callbacks in series in its own thread:
| Sequential Callbacks | |
|---|---|
The background thread that listens to the event executes the callbacks by spawning new threads:
The event listening task creates new tasks in the running event loop:
In GUI frameworks like PyQt, you cannot paint the GUI from the event thread. You would need to use signals and slots or other mechanisms to update the GUI to hand over the data.
To unsubscribe:
| Unsubscription | |
|---|---|
All subscriptions to the same event are removed.
Payload Schema
A schema for the payload may be supplied using pydantic or JSON schema:
There is no validation on the client side currently implemented in
hololinked.client. This will be added in future releases.
Schema as seen in Thing Description
Thing Description Metadata
| Key | Supported | Comment |
|---|---|---|
| subscription | ✖ | |
| data | ✔ | payload schema for the event |
| dataResponse | ✖ | will be supported in a future release |
| cancellation | - | Server sent events can be cancelled by the client directly |