Struct actyxos_sdk::event::Event[][src]

pub struct Event<T> {
    pub lamport: LamportTimestamp,
    pub stream: StreamInfo,
    pub timestamp: TimeStamp,
    pub offset: Offset,
    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 stream.source uniquely identify the event and give rise to a total order (first by Lamport timestamp, then by source ID; a source — an ActyxOS 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 EventService client will provide 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 actyxos_sdk::event::{Event, Payload};

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

let event: Event<Payload> = Event::mk_test("semantics", "name", "{\"x\":42}").unwrap();
let my_event: Event<MyPayload> = event.extract::<MyPayload>().expect("expected MyPayload");

Fields

lamport: LamportTimestampstream: StreamInfotimestamp: TimeStampoffset: Offsetpayload: T

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.

Create an Event instance for testing purposes.

Caveat emptor: This will not generate proper timestamps and two such events will compare equal to each other (so cannot be put into collections without first making their Lamport timestamps unique).

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

Formats the value using the given formatter. Read more

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

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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.

Should always be Self

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)

recently added

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

Converts the given value to a String. 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.

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