Skip to content

Built in Sources and Sinks

Gabriele Baldoni edited this page Mar 7, 2023 · 2 revisions

Built-in Sources and Sinks

Zenoh-Flow provides tight integration with Zenoh by providing built-in sources and sinks to retrieve and publish data to an existing Zenoh network.

Such built-in components allow a faster and easier way to get data published/subscribed from Zenoh to being processed by Zenoh-Flow operators.

How to use

In order to use the built-in sources and sink in your flow you need to leverage the new URI: builtin://zenoh, this will tell Zenoh-Flow that you would like to use the built-in components.

For every built-in source/sink that you want to use, it is also necessary to specify the configuration. The configuration has to be a Key-Value map, in which the Key represents the name of the output/input you want to create and the Value the associated Zenoh Key Expression.

Let's look for an example. Imagine we want a built-in source to insert into the flow data coming from two different key expressions:

  • my-fancy-home/sensors/pool/temperature
  • my-fancy-home/sensor/roof/light

In this case, I would define the source in my descriptor as follows:

sources:
  - id: data-from-sensors
    configuration:
      temp: my-fancy-home/sensors/pool/temperature
      light: my-fancy-home/sensor/roof/light
    descriptor: builtin://zenoh

Zenoh-Flow will understand that the source data-from-sensors has two outputs, each associated with the given key expression. It will take care to produce the correct output every time new data is being produced for the defined key expression.

For more details on Zenoh's key expression please refer to Zenoh documentation.

The same approach applies to sinks. Let's imagine we want a sink that publishes data to two different key expressions:

  • my-fancy-home/porch/light
  • my-fancy-home/porch/warming

In this case I would define my sink as follow:

sinks:
  - id: command-porch
    configuration:
      light: my-fancy-home/porch/light
      warming: my-fancy-home/porch/warming
    descriptor: builtin://zenoh

Zenoh-Flow will understand that the sink command-porch has two inputs, each associated with the given key expression. Thus every time data is arriving on one of the inputs Zenoh Flow is going to publish that data to the corresponding key expression using Zenoh.

Let's now look at a simple example flow using the source and sink we just defined:

flow: my-house-control

sources:
  - id: data-from-sensors
    configuration:
      temp: my-fancy-home/sensors/pool/temperature
      light: my-fancy-home/sensor/roof/light
    descriptor: builtin://zenoh

sinks:
  - id: command-porch
    configuration:
      light: my-fancy-home/porch/light
      warming: my-fancy-home/porch/warming
    descriptor: builtin://zenoh

operators:
  - id: warming-control
    descriptor: file://....

  - id: light-control
    descriptor: file://....



links:

  - from:
      node: data-from-sensors
      output: temp
    to:
      node: warming-control
      input: temp

  - from:
      node: data-from-sensors
      output: light
    to:
      node: light-control
      input: sun-level

  - from:
      node: warming-control
      output: warming-level
    to:
      node: command-porch
      input: warming

  - from:
      node: light-control
      output: light-level
    to:
      node: command-porch
      input: light

That's all, so from now on it is possible to retrieve data from Zenoh inside a flow without needing to write specific sources and sinks, but instead leverage the built-in ones provided by Zenoh-Flow.

Note: In the future more builtin Source/Sink could be added (i.e., DDS, ROS, ROS 2, ...)

Clone this wiki locally