Crate actyx_sdk[][src]

Expand description

Actyx makes it easy to run distributed applications on multiple nodes. It is a piece of software that allows you to run your own apps on one or more edge devices and have these apps seamlessly communicate and share data with each other.

This crate defines the data types needed for communicating with Actyx and provides Rust bindings for the Actyx APIs. It also provides serialization instances for processing the events with differential-dataflow under the "dataflow" feature flag.

Examples

Below you find a full example using the EventService client that retrieves some events. Please adapt the semantics to match your stored events in order to see output.

Note: this example needs the client feature to compile

use actyx_sdk::{
  app_id, AppManifest, HttpClient,
  service::{EventService, Order, QueryRequest, QueryResponse},
};
use futures::stream::StreamExt;
use url::Url;

#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
  // add your app manifest, for brevity we will use one in trial mode
  let app_manifest = AppManifest::new(
      app_id!("com.example.my-awesome-app"),
      "display name".into(),
      "0.1.0".into(),
      None,
  );

  // Url of the locally running Actyx node
  let url = Url::parse("http://localhost:4454")?;
  // client for
  let service = HttpClient::new(url, app_manifest).await?;

  // retrieve largest currently known event stream cursor
  let offsets = service.offsets().await?.present;

  // all events matching the given subscription
  // sorted backwards, i.e. youngest to oldest
  let mut events = service
      .query(QueryRequest {
          lower_bound: None,
          upper_bound: offsets,
          query: "FROM 'MyFish'".parse()?,
          order: Order::Desc,
      })
      .await?;

  // print out the payload of each event
  // (cf. Payload::extract for more options)
  while let Some(QueryResponse::Event(event)) = events.next().await {
      println!("{}", event.payload.json_value());
  }
  Ok(())
}

Feature flags

The default is to provide only the data types with serialization and deserialization support for serde. The following features can be enabled in addition:

Modules

language
legacy
service
types

Types that you may want to use in describing the event payload data

Macros

app_id

Macro for constructing an AppId literal.

arcval_scalar

Helper macro to create interned string types

fish_name

Macro for constructing a FishName literal.

semantics

Macro for constructing a Semantics literal.

source_id

Macro for constructing a SourceId literal.

tag

Macro for constructing a Tag literal.

tags

Macro for constructing a set of Tag values.

Structs

AppId

The app ID denotes a specific app (sans versioning)

AppManifest
Event

Events are delivered in this envelope together with their metadata

EventKey

The sort key of an event

HttpClient
LamportTimestamp

A logical timestamp taken from a Lamport clock

Metadata
NodeId

The Actyx node identifier

Offset

Event offset within a SourceId’s stream

OffsetMap

Multi-dimensional cursor for event streams: an OffsetMap describes the set of events given by the event streams of each included source up to the associated Offset.

OffsetOrMin

Event offset within a SourceId’s stream or MIN value

Opaque

A ref-counted slice of memory holding a compact binary representation of an event payload

Payload

Compact binary storage of events created when they are received from the Event Service

StreamId

The unique identifier of a single event stream emitted by an Actyx node

StreamNr

StreamNr. Newtype alias for u64

Tag

A Tag that semantically characterises an event.

TagSet

A set of tags in canonical iteration order

Timestamp

Microseconds since the UNIX epoch, without leap seconds and in UTC

Url

A parsed URL record.

Enums

ParseError