Skip to main content

nstreams_core/
stream.rs

1use async_trait::async_trait;
2use futures::Stream;
3
4use crate::event::StreamEvent;
5use crate::filter::StreamFilter;
6use crate::namespace::Namespace;
7
8/// Publishes raw events to the write-side RabbitMQ queue.
9#[async_trait]
10pub trait WriteQueueBackend: Send + Sync {
11    async fn publish<N: Namespace>(
12        &self,
13        namespace: &N,
14        payload: &[u8],
15        filter_value: Option<&str>,
16    ) -> crate::Result<()>;
17}
18
19/// Manages read-side RabbitMQ streams and live consumption.
20#[async_trait]
21pub trait ReadStreamBackend: Send + Sync {
22    /// Returns true when the read stream already exists.
23    async fn stream_exists<N: Namespace>(&self, namespace: &N) -> crate::Result<bool>;
24
25    /// Create a read stream sized for the namespace's retention policy.
26    async fn create_read_stream<N: Namespace>(
27        &self,
28        namespace: &N,
29        max_event_bytes: u64,
30    ) -> crate::Result<()>;
31
32    /// Publish a versioned event to the read stream.
33    async fn publish_to_stream(&self, event: &StreamEvent) -> crate::Result<()>;
34
35    /// Publish a batch of historical events during stream bootstrap.
36    async fn populate_stream(&self, events: &[StreamEvent]) -> crate::Result<()>;
37
38    /// Subscribe to the live tail of a read stream.
39    async fn subscribe_live<N: Namespace>(
40        &self,
41        namespace: &N,
42        filter: Option<&StreamFilter>,
43    ) -> crate::Result<impl Stream<Item = crate::Result<StreamEvent>> + Send>;
44}