Expand description
Zenoh /zeno/ is a stack that unifies data in motion, data at rest and computations. It elegantly blends traditional pub/sub with geo distributed storage, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.
Before delving into the examples, we need to introduce few Zenoh concepts.
First off, in Zenoh you will deal with Resources, where a resource is made up of a
key and a value. The other concept you’ll have to familiarize yourself with are
key expressions, such as robot/sensor/temp
, robot/sensor/*
, robot/**
, etc.
As you can gather, the above key expression denotes set of keys, while the *
and **
are wildcards representing respectively (1) an arbitrary string of characters, with the exclusion of the /
separator, and (2) an arbitrary sequence of characters including separators.
Below are some examples that highlight these key concepts and show how easy it is to get started with.
§Examples
§Publishing Data
The example below shows how to produce a value for a key expression.
#[tokio::main]
async fn main() {
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
session.put("key/expression", "value").await.unwrap();
session.close().await.unwrap();
}
§Subscribe
The example below shows how to consume values for a key expressions.
use futures::prelude::*;
#[tokio::main]
async fn main() {
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session.declare_subscriber("key/expression").await.unwrap();
while let Ok(sample) = subscriber.recv_async().await {
println!("Received: {:?}", sample);
};
}
§Query
The example below shows how to make a distributed query to collect the values associated with the resources whose key match the given key expression.
use futures::prelude::*;
#[tokio::main]
async fn main() {
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let replies = session.get("key/expression").await.unwrap();
while let Ok(reply) = replies.recv_async().await {
println!(">> Received {:?}", reply.result());
}
}
Modules§
- Payload primitives
- Callback handler trait.
- Key expression are Zenoh’s address space.
- Liveliness primitives
- matching
unstable
- Pub/sub primitives
- Quality of service primitives
- Query/reply primitives
- Sample primitives
- Scouting primitives
- Zenoh
Session
and associated types - shm
shared-memory
andunstable
Shared memory. - Timestamp support
Structs§
- Zenoh configuration.
- The entrypoint of the zenoh API.
Traits§
- A resolvable execution, either sync or async
- Zenoh’s trait for resolving builder patterns.
- Synchronous execution of a resolvable
Functions§
- A utility function to enable the tracing formatting subscriber.
- Open a zenoh
Session
. - Scout for routers and/or peers.
- A utility function to enable the tracing formatting subscriber.
Type Aliases§
- A zenoh error.
- A zenoh result.