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.
use zenoh::prelude::r#async::*;
#[tokio::main]
async fn main() {
let session = zenoh::open(config::default()).res().await.unwrap();
session.put("key/expression", "value").res().await.unwrap();
session.close().res().await.unwrap();
}
§Subscribe
The example below shows how to consume values for a key expresison.
use futures::prelude::*;
use zenoh::prelude::r#async::*;
#[tokio::main]
async fn main() {
let session = zenoh::open(config::default()).res().await.unwrap();
let subscriber = session.declare_subscriber("key/expression").res().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::*;
use zenoh::prelude::r#async::*;
#[tokio::main]
async fn main() {
let session = zenoh::open(config::default()).res().await.unwrap();
let replies = session.get("key/expression").res().await.unwrap();
while let Ok(reply) = replies.recv_async().await {
println!(">> Received {:?}", reply.sample);
}
}
Re-exports§
pub use zenoh_config as config;
pub use zenoh_buffers as buffers;
Modules§
- Callback handler trait.
- Tools to access information about the current zenoh
Session
. - Key expression are Zenoh’s address space.
- liveliness
unstable
Liveliness primitives. - A “prelude” for crates using the
zenoh
crate. - A map of key/value (String,String) properties.
- Publishing primitives.
- Query primitives.
- Queryable primitives.
- Sample primitives
- Scouting primitives.
- Selector to issue queries
- Subscribing primitives.
- Time related types and functions.
- Value primitives.
Macros§
- Equivalent to
keyexpr::new
, but the check is run at compile-time and will throw a compile error in case of failure. - Create format modules from a format specification.
- Write a set of values into a
Formatter
and then builds it into anOwnedKeyExpr
, stopping as soon as a value doesn’t fit the specification for its field. - Write a set of values into a
Formatter
, stopping as soon as a value doesn’t fit the specification for its field. Contrary tokeformat
doesn’t build the Formatter into a Key Expression.
Structs§
- A zenoh session.
Enums§
Constants§
Traits§
- Functions to create zenoh entities
- A trait implemented by types that can be undeclared.
Functions§
- Open a zenoh
Session
. - Scout for routers and/or peers.
Type Aliases§
- A zenoh error.
- A zenoh result.