Advanced Configuration¶
Generating Config Files¶
ros-z can generate JSON5 config files matching rmw_zenoh_cpp defaults. This is opt-in via the generate-configs feature flag.
Basic Generation¶
Output location:
target/debug/build/ros-z-*/out/ros_z_config/
├── DEFAULT_ROSZ_ROUTER_CONFIG.json5
└── DEFAULT_ROSZ_SESSION_CONFIG.json5
Custom Output Directory¶
Specify a custom directory using the ROS_Z_CONFIG_OUTPUT_DIR environment variable:
Absolute path:
Relative path (from package root):
From workspace root:
Tip
Generated files include inline comments explaining each setting, making them perfect documentation references.
Using Generated Files¶
let ctx = ZContextBuilder::default()
.with_config_file("./config/DEFAULT_ROSZ_SESSION_CONFIG.json5")
.build()?;
Configuration Reference¶
Key Settings Explained¶
| Setting | Router | Session | Purpose |
|---|---|---|---|
| Mode | router |
peer |
Router relays messages, peers connect directly |
| Listen Endpoint | tcp/[::]:7447 |
- | Router accepts connections |
| Connect Endpoint | - | tcp/localhost:7447 |
Session connects to router |
| Multicast | Disabled | Disabled | Uses TCP gossip for discovery |
| Unicast Timeout | 60s | 60s | Handles slow networks/large deployments |
| Query Timeout | 10min | 10min | Long-running service calls |
| Max Sessions | 10,000 | - | Supports concurrent node startup |
| Keep-Alive | 2s | 2s | Optimized for loopback |
Note
These defaults target ROS 2 deployments and match rmw_zenoh_cpp exactly. Only modify them if you have specific performance requirements.
Example: Full Session Config¶
A typical generated DEFAULT_ROSZ_SESSION_CONFIG.json5 looks like this. Copy it, edit
the fields you need, and pass it to .with_config_file():
{
// Session mode: "peer" connects to a router, "router" acts as one
mode: "peer",
connect: {
endpoints: [
// Connect to the local router by default
"tcp/localhost:7447",
],
// Retry failed connections every 5 seconds
retry: {
period_init_ms: 5000,
period_max_ms: 5000,
},
},
listen: {
endpoints: [],
},
scouting: {
multicast: {
// Multicast disabled — ros-z uses router-based discovery
enabled: false,
},
gossip: {
enabled: true,
multihop: false,
},
},
transport: {
unicast: {
// Timeout for initial connection handshake
open_timeout: 60000,
// Keep-alive interval (optimised for loopback traffic)
keepalive: 2,
},
qos: {
enabled: true,
},
},
// Timeout for service calls (set high for long-running operations)
queries_default_timeout: 600000,
}
Common Customisations¶
Connect to a Remote Router¶
Replace localhost with the router's IP address or hostname:
Or set it in code without editing a file:
Connect to Multiple Routers¶
For resilient deployments with redundant routers:
Reduce Service Call Timeout¶
The default 10-minute query timeout is conservative. For real-time applications:
Enable TLS¶
For encrypted inter-robot communication:
connect: {
endpoints: ["tls/10.0.0.1:7448"],
},
transport: {
unicast: {
lowlatency: false,
qos: { enabled: true },
tls: {
server_name: "robot-router",
root_ca_certificate: "/etc/zenoh/ca.pem",
},
},
},
Validating a Config File¶
Before deploying a modified config, verify it parses correctly:
# Run a short-lived session — if it connects cleanly, the config is valid
RUST_LOG=zenoh=info cargo run --example z_pubsub -- --config ./my_config.json5
A valid config produces:
An invalid config produces a parse error before the session opens.