logo

Struct actyx_sdk::Event[][src]

pub struct Event<T> {
    pub key: EventKey,
    pub meta: Metadata,
    pub payload: T,
}
Expand description

Events are delivered in this envelope together with their metadata

Metadata

Ordering and equality do not depend on the type of payload: lamport and key.stream uniquely identify the event and give rise to a total order (first by Lamport timestamp, then by stream ID;  an Actyx node   will never use the same Lamport timestamp more than once).

The contained Lamport timestamp tracks the causal order of events, which may not always be linked to or consistent with real time, especially when events were produced by devices that were not communicating for some time period. This implies that the wall clock timestamp may go backwards when consuming an ordered event stream (this would also be the case due to clock skew between devices).

Illustrative example: two groups of nodes are separated from each other for some time period, for example due to traveling through an area without network coverage. Their logical clocks may advance at different speeds because the number of events created in each group may be different. When sorting by Lamport timestamp, the events from the group with the lower event rate will tend to be sorted earlier than the events from the other group, regardless of the wall clock time at which they occurred.

It is desirable to sort by Lamport timestamps because they provide the correct (intuitive) sort order when nodes are properly communicating, which is the common case. Using device hardware clocks has proven to be quite unreliable because they may jump forward and backward due to human or machine error.

Payload

The envelope contains a generic Payload payload type, you may use the extract method to parse the payload as a more specific object.

use serde::{Deserialize, Serialize};
use actyx_sdk::{Event, Payload};

#[derive(Serialize, Deserialize, Debug, Clone)]
struct MyPayload {
    x: f64,
    y: Option<f64>,
}

let payload = Payload::from_json_str(r#"{"x":1.3}"#).unwrap();

Fields

key: EventKey

Uniquely identifying event key. Used for sorting.

meta: Metadata

Metadata incl. tags, timestamp and app ID

payload: T

The actual event payload

Implementations

Try to extract the given type from the generic payload and return a new event envelope if successful. The produced payload is deserialized as efficiently as possible and may therefore still reference memory owned by the Payload. You may need to .clone() it to remove this dependency.

Trait Implementations

Write any additional information about &self beyond its binary representation. Read more

Reports the number of further bytes required to entomb self.

Recover any information for &mut self not evident from its binary representation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Ensure that the given event is no longer contained within this OffsetMap.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Compare self to key and return true if they are equal.

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Casts the value.

OverflowingCasts the value.

Scrape the references from an impl Read. Read more

Should always be Self

Casts the value.

Casts the value.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

UnwrappedCasts the value.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Casts the value.

WrappingCasts the value.