The primary role of the Zenoh router is to act as a discovery service for ROS nodes running on the same host. When a node starts, it automatically tries to connect to the local Zenoh router. If the connection fails, the node waits until the router becomes available. The router shares the locators (IP + port) of each node with others, allowing them to automatically establish peer-to-peer connections. Once nodes are connected, they no longer need the router to communicate with each other.
To test this, open three different terminals within the same container (using the login_container.sh
script under the docker
directory) and run the demo_nodes_cpp
package’s talker
and listener
:
ros2 run demo_nodes_cpp talker
ros2 run rmw_zenoh_cpp rmw_zenohd
ros2 run demo_nodes_cpp listener
CTRL+C
to stop the Zenoh router. The talker and listener will continue exchanging messages without the router.[!WARNING] By default a Node will check if a Zenoh router is available at startup once. To make the Node skip this Zenoh router check or attempt its discovery more than once define the following environment variable for each of your Node accordingly:
ZENOH_ROUTER_CHECK_ATTEMPTS=-1
# For skipping checkZENOH_ROUTER_CHECK_ATTEMPTS=0
# For checking maximum value of attempts
You can also test with a ROS service:
ros2 run demo_nodes_cpp add_two_ints_server
ros2 run demo_nodes_cpp add_two_ints_client
And with an Action:
ros2 run action_tutorials_cpp fibonacci_action_server
ros2 run action_tutorials_cpp fibonacci_action_client
Additionally, you can use the ros2
command-line tool to inspect the system:
ros2 node list
ros2 topic list
ros2 service list
ros2 action list
Even if the Zenoh router is stopped, the ros2
command-line tool will continue to function.
Why?