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: LamportTimestamp
stream: StreamInfo
timestamp: TimeStamp
offset: Offset
payload: 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
Performs the +=
operation. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
Ensure that the given event is no longer contained within this OffsetMap.
Auto Trait Implementations
impl<T> !RefUnwindSafe for Event<T>
impl<T> !UnwindSafe for Event<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Performs the conversion.
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