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§

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§

Type Aliases§