EventSubscriber

Trait EventSubscriber 

Source
pub trait EventSubscriber {
    type SourceId: Eq;
    type Event;
    type Error;

    // Required method
    fn subscribe_all(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Persisted<Self::SourceId, Self::Event>, Self::Error>> + Send + '_>>, Self::Error>> + Send + '_>>;
}
Expand description

Component to let users subscribe to newly-inserted events into the EventStore.

Check out [subscribe_all] for more information.

Additional information can be found in the Volatile Subscription section of eventstore.com

Required Associated Types§

Source

type SourceId: Eq

Type of the Source id, typically an AggregateId.

Source

type Event

Event type stored in the EventStore, typically an Aggregate::Event.

Source

type Error

Possible errors returned when receiving events from the notification channel.

Required Methods§

Source

fn subscribe_all( &self, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Persisted<Self::SourceId, Self::Event>, Self::Error>> + Send + '_>>, Self::Error>> + Send + '_>>

Subscribes to all new events persisted in the EventStore, from the moment of calling this function, in the future.

Since this is a long-running stream, make sure not to block or await the full computation of the stream.

Prefer using a while let consumer for this EventStream:

let stream = subscriber.subscribe_all().await?;

while let Some(event) = stream.next().await {
    // Do stuff with the received event...
}

Implementors§

Source§

impl<Id, Event> EventSubscriber for EventStore<Id, Event>
where Id: Hash + Eq + Sync + Send + Clone, Event: Sync + Send + Clone,