# Run a simple Zenoh pub/sub example

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/)
- [Build scalable communication systems with Eclipse Zenoh](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/1_intro-zenoh/)
- [Get started with Zenoh on Raspberry Pi and Arm Linux](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/2_zenoh-install/)
- [Containerize and deploy Zenoh across multiple Raspberry Pi devices](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/3_zenoh-multinode/)
- [Run a simple Zenoh pub/sub example](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/4_zenoh-ex1-pubsub/)
- [Run a Zenoh storage and query example](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/5_zenoh-ex2-storagequery/)
- [Run a Zenoh queryable node for on-demand edge computation](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/6_zenoh-ex3-queryable/)
- [Run a Zenoh queryable with parameterized Rust computation](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/7_zenoh-querycomp/)
- [Next Steps](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/_next-steps/)

## Test Zenoh pub/sub across two devices
This example demonstrates how to use Zenoh’s real-time publish/subscribe model to exchange messages between two Raspberry Pi devices over a local network.

Pub/sub is a core Zenoh communication pattern where data producers (publishers) send values to a key, and data consumers (subscribers) receive updates for matching key expressions. In this case, the subscriber listens for all messages published under the key expression `demo/example/**`, which matches any topic that begins with `demo/example/`. This enables flexible topic filtering and lightweight data dissemination across distributed systems.

## Start the subscriber node
Run the subscriber example on one of the Raspberry Pi systems:
```bash
cd ~/zenoh/target/release/examples
./z_sub
```

## Start the publisher node
Then, log in to the other Raspberry Pi and run the publisher:
```bash
cd ~/zenoh/target/release/examples
./z_pub
```

> You can run both `z_sub` and `z_pub` on the same device for testing, but running them on separate Raspberry Pis demonstrates Zenoh’s distributed discovery and cross-node communication.

## Observe the pub/sub data flow
The results are shown below:

![Simple Pub/Sub](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/zenoh_ex1.gif "Simple Pub/Sub")

The left-side window shows the `z_sub` program. It receives values with the key `demo/example/zenoh-rs-pub` continuously published by `z_pub` running in the right-side window.

This example confirms that Zenoh’s zero-configuration peer discovery and real-time pub/sub communication are working correctly across physical nodes.
