pub struct Subscription<Repo> {
pub repo: Repo,
pub id: Uuid,
pub name: SubscriptionName,
pub target_stream: SubscriptionName,
}
Expand description
A subscription to a stream of events. Subscriptions read events from a target stream
and manage a tracking stream to measure their progress. Subscriptions generate their own
ids when they are created, meaning every subscription is unique and replays the target
stream from the beginning. In order to avoid replaying the target stream, use the
Subscription::resume
method and give it the id of an existing subscription.
Fields§
§repo: Repo
The given repository that the subscriber reads from.
id: Uuid
The id of the subscription. This is used to track the subscription’s progress.
name: SubscriptionName
The name of the stream that this connection marks reads in. This is essentially the identity of the connection. Changing this will cause the connection to read from the beginning of the target stream. The name of the stream that the subscriber tracks its reads in. This is more or less the identity of the subscriber. Changing this will cause the subscriber to read from the beginning of the target stream.
target_stream: SubscriptionName
The name of the stream that this connection is reading from. The connection will ignore events from other streams.
Implementations§
Source§impl<Repo> Subscription<Repo>
impl<Repo> Subscription<Repo>
Sourcepub fn init(repo: &Repo, name: impl SubscriptionTopic) -> Result<Self, String>
pub fn init(repo: &Repo, name: impl SubscriptionTopic) -> Result<Self, String>
Create a new subscription to a stream of events, generating a new id for the subscription.
Sourcepub fn resume(
repo: &Repo,
id: Uuid,
name: impl SubscriptionTopic,
) -> Result<Self, String>
pub fn resume( repo: &Repo, id: Uuid, name: impl SubscriptionTopic, ) -> Result<Self, String>
Resume a subscription to a stream of events, using the given id to track the subscription’s progress. Use this to avoid replaying the target stream entirely, instead picking up at the last read position.
Sourcepub fn stream(&self) -> SubscriptionStream
pub fn stream(&self) -> SubscriptionStream
Turn the subscription into a background process that you can listen to asynchronously.
This returns a SubscriptionStream
that you can use to listen to the subscription,
and manipulate with [StreamExt
] methods.
Sourcepub fn worker<FrameService>(
&self,
service: FrameService,
) -> Result<SubscriptionWorker, EventRepoError>
pub fn worker<FrameService>( &self, service: FrameService, ) -> Result<SubscriptionWorker, EventRepoError>
Create a background process and process all pending events in the target stream using the given frame service.
Sourcepub async fn call_with_service<FrameService>(
&self,
service: FrameService,
) -> Result<(), EventRepoError>
pub async fn call_with_service<FrameService>( &self, service: FrameService, ) -> Result<(), EventRepoError>
Process all pending events in the target stream.
Sourcepub async fn last_read_position(&self) -> i64
pub async fn last_read_position(&self) -> i64
Get the last read position for a subscriber.
Sourcepub async fn pending_events(&self) -> Result<EventLog, EventRepoError>
pub async fn pending_events(&self) -> Result<EventLog, EventRepoError>
Get all of the events in the target stream that have occurred since the last read marker.
Sourcepub async fn poll_events(&self) -> Result<EventLog, EventRepoError>
pub async fn poll_events(&self) -> Result<EventLog, EventRepoError>
Poll for any pending events in the target stream.
Sourcepub async fn log_last_read(&self, position: i64) -> Result<(), EventRepoError>
pub async fn log_last_read(&self, position: i64) -> Result<(), EventRepoError>
Log the last read position for a subscriber. This leverages markers.
Trait Implementations§
Source§impl<Repo: Clone> Clone for Subscription<Repo>
impl<Repo: Clone> Clone for Subscription<Repo>
Source§fn clone(&self) -> Subscription<Repo>
fn clone(&self) -> Subscription<Repo>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more