Zenohex (Zenohex v0.9.1-beta.1)

Copy Markdown View Source

Zenohex is a thin Elixir wrapper around Zenoh, implemented using Rustler.

To learn how to use this library, check the example implementations in the following directory:

Summary

Functions

Deletes data matching the given key_expr.

Query data with the given selector.

Publishes a payload to the specified key_expr.

Scouts for routers or peers.

Functions

delete(key_expr, opts \\ [])

@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, reason :: term()}

Deletes data matching the given key_expr.

Internally opens a session, deletes the data, and ensures the session is closed.

Parameters

get(selector, timeout, opts \\ [])

@spec get(String.t(), non_neg_integer(), keyword()) ::
  {:ok, [Zenohex.Sample.t() | Zenohex.Query.ReplyError.t()]}
  | {:error, :timeout}
  | {:error, reason :: term()}

Query data with the given selector.

Internally opens a session, performs the query, and ensures the session is closed.

Parameters

  • selector : The selector to query.
  • timeout : Timeout in milliseconds to wait for query replies.
  • opts : Additional options. See Zenohex.Session.get/4 for details.

put(key_expr, payload, opts \\ [])

@spec put(String.t(), binary(), keyword()) :: :ok | {:error, reason :: term()}

Publishes a payload to the specified key_expr.

Internally opens a session, performs the publish, and ensures the session is closed.

Parameters

  • key_expr : The key expression to publish to.
  • payload : The binary payload to publish.
  • opts : Additional options. See Zenohex.Session.put/4 for details.

scout(what, config, timeout)

@spec scout(Zenohex.Scouting.what(), Zenohex.Config.t(), non_neg_integer()) ::
  {:ok, [Zenohex.Scouting.Hello.t()]}
  | {:error, :timeout}
  | {:error, reason :: term()}

Scouts for routers or peers.

This function discovers either :peer or :router nodes based on the given configuration. It blocks until a response is received or the timeout is reached.

Parameters

  • what: Either :peer or :router, indicating what type of node to search for.
  • config: The Zenoh configuration used for the scout operation.
  • timeout: The maximum time to wait (in milliseconds) before giving up.

Examples

iex> config = Zenohex.Config.default()
iex> {:ok, hellos} = Zenohex.scout(:peer, config, 1000)