Struct Subscription

Source
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>
where Repo: EventRepo + Clone,

Source

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.

Source

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.

Source

pub fn stream(&self) -> SubscriptionStream
where Repo: Clone + Send + Sync + 'static,

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.

Source

pub fn worker<FrameService>( &self, service: FrameService, ) -> Result<SubscriptionWorker, EventRepoError>
where Repo: Clone + Send + Sync + 'static, FrameService: Service<Frame> + Send + Sync + 'static, FrameService::Future: Send, <FrameService as Service<Frame>>::Response: Into<Frame>, <FrameService as Service<Frame>>::Error: Into<Frame>,

Create a background process and process all pending events in the target stream using the given frame service.

Source

pub async fn call_with_service<FrameService>( &self, service: FrameService, ) -> Result<(), EventRepoError>
where Repo: Clone + Send + Sync + 'static, FrameService: Service<Frame> + Send + Sync + 'static, FrameService::Future: Send,

Process all pending events in the target stream.

Source

pub async fn last_read_position(&self) -> i64

Get the last read position for a subscriber.

Source

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.

Source

pub async fn poll_events(&self) -> Result<EventLog, EventRepoError>
where Repo: Clone + Send + Sync + 'static,

Poll for any pending events in the target stream.

Source

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>

Source§

fn clone(&self) -> Subscription<Repo>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Repo: Debug> Debug for Subscription<Repo>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Repo> Freeze for Subscription<Repo>
where Repo: Freeze,

§

impl<Repo> RefUnwindSafe for Subscription<Repo>
where Repo: RefUnwindSafe,

§

impl<Repo> Send for Subscription<Repo>
where Repo: Send,

§

impl<Repo> Sync for Subscription<Repo>
where Repo: Sync,

§

impl<Repo> Unpin for Subscription<Repo>
where Repo: Unpin,

§

impl<Repo> UnwindSafe for Subscription<Repo>
where Repo: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,