Skip to main content

Subscriber Example

This tool is intended as an example of subscribing to a Nimble data stream. You can find it under tools/zmq/subscriber in the release package.

To run the example:

user@host:~$ docker-compose up --build

## Code Breakdown

First, we need to establish a connection to the publisher socket
ctx = zmq.Context()
sub = ctx.socket(zmq.SUB)
sub.setsockopt(zmq.RCVTIMEO, 10000)

With the connection established you can start listening for data, and parsing the topic. There are currently 3 topics: channel/id, fps and latency.

data = data_socket.recv_multipart()
topic = data[0].decode('utf-8')

The fps and latency topic are simple reporting streams on overall performance health of the pipeline, the majority of the data is contained within the channel/id topic(s). Extract out of the channel id and metadata as a python dictionary:

channel_id = int(topic.split("/")[1])
metadata = json.loads(data[1].decode('utf-8'))

Parsing the metadata is outside the scope of this document please refer to the metadata schemas.

For a detailed description of the ZMQ publishing protocol please refer to: Data Publishing Endpoint (PUB-SUB) in the ZMQ API.