Events
Events are pushed to the client through a publish-subscribe mechanism through all the protocols. Call 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 backgound:
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 it:
The callback function(s) must accept a single argument - an instance of SSE object. The payload can be accessed as 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 newer 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
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 |