zserio.pubsub module

The module provides classes for Zserio Pub/Sub.

exception zserio.pubsub.PubsubException[source]

Bases: PythonRuntimeException

Exception thrown in case of an error in Zserio Pub/Sub.

class zserio.pubsub.PubsubInterface[source]

Bases: object

Interface for Pub/Sub client backends.

publish(topic: str, data: bytes, context: Any | None = None) None[source]

Publishes given data as a specified topic.

Parameters:
  • topic – Topic definition.

  • data – Data to publish.

  • context – Context specific for a particular Pub/Sub implementation.

Raises:

PubsubException – If the publishing fails.

subscribe(topic: str, callback: Callable[[str, bytes], None], context: Any | None = None) int[source]

Subscribes a topic.

Parameters:
  • topic – Topic definition to subscribe. Note that the definition format depends on the particular Pub/Sub backend implementation and therefore e.g. wildcards can be used only if they are supported by Pub/Sub backend.

  • callback – Callback to be called when a message with the specified topic arrives.

  • context – Context specific for a particular Pub/Sub implementation.

Returns:

Subscription ID.

Raises:

PubsubException – If subscribing fails.

unsubscribe(subscription_id: int) None[source]

Unsubscribes the subscription with the given ID.

Parameters:

id – ID of the subscription to be unsubscribed.

Raises:

PubsubException – If unsubscribing fails.