Crate zenoh

Source
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§

bytes
Payload primitives
config
Configuration to pass to open and scout functions and associated constants.
handlers
Callback handler trait.
key_expr
Key expression are Zenoh’s address space.
liveliness
Liveliness primitives
matchingunstable
pubsub
Pub/sub primitives
qos
Quality of service primitives
query
Query/reply primitives
sample
Sample primitives
scouting
Scouting primitives
session
Zenoh Session and associated types
shmunstable
Shared memory.
time
Timestamp support

Structs§

Config
Zenoh configuration.
Session
The entrypoint of the zenoh API.

Traits§

Resolvable
A resolvable execution, either sync or async
Resolve
Zenoh’s trait for resolving builder patterns.
Wait
Synchronous execution of a resolvable

Functions§

init_log_from_env_or
A utility function to enable the tracing formatting subscriber.
open
Open a zenoh Session.
scout
Scout for routers and/or peers.
try_init_log_from_env
A utility function to enable the tracing formatting subscriber.

Type Aliases§

Error
A zenoh error.
Result
A zenoh result.