Two services on a balena device exchange messages through Zenoh using a pub/sub pattern. A third service (Zenoh router) is included for reference and is recommended when deploying multiple devices in a robotic swarm to reduce multicast traffic overhead.
By default, the publisher and subscriber do not require each other to be running—they automatically discover each other through Zenoh's multicast scouting mechanism. When the publisher publishes data, the subscriber (once it joins) will automatically receive it without any explicit broker coordination.
Optionally, you can configure them to use the zenoh-router as a central broker (similar to MQTT), which is useful in swarms where you want to minimize multicast traffic or where nodes may not have direct multicast connectivity. In that case, both services would connect to the router in client mode instead of relying on peer discovery.
zenoh-router: Custom image built from the official Zenoh router base (eclipse/zenoh:1.7.1) with config baked in fromrouter/zenoh.json5. Optional in this example (peer-to-peer discovery works by default via multicast), but recommended for multi-device deployments where a centralized router can reduce multicast discovery and routing overhead across the swarm.publisher: Python + zenoh 1.7.1, publishes todemo/exampleevery 2s. Discovers subscribers automatically via multicast or can connect to the router in client mode.subscriber: Rust + zenoh 1.7.1, prints everything it receives ondemo/example. Discovers publishers automatically via multicast or can connect to the router in client mode.
- Install the balena CLI and log in (
balena login). - Push to your fleet:
balena push <fleetSlug>. - Tail logs:
balena logs <deviceUUID>and you should see publisher and subscriber output.
docker-compose up --buildYou will see the publisher emit messages and the subscriber print them.
ZENOH_CONNECT: connect endpoint for publisher/subscriber (defaulttcp/zenoh-router:7447).ZENOH_KEY: shared key expression (defaultdemo/example).ZENOH_VALUE: base text the publisher sends.
- Port
7447is published by the router so external tools can connect to the Zenoh network if needed. - Default device types in
balena.ymlcan be adjusted to match your hardware fleet.