Skip to main content

nstreams_core/
stream.rs

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