nstreams-core 0.3.1

Generic versioned event stream handler with history replay
Documentation
use async_trait::async_trait;
use futures::Stream;

use crate::event::StreamEvent;
use crate::filter::StreamFilter;
use crate::namespace::Namespace;

/// Publishes raw events to the write-side RabbitMQ queue.
#[async_trait]
pub trait WriteQueueBackend: Send + Sync {
    async fn publish<N: Namespace>(
        &self,
        namespace: &N,
        payload: &[u8],
        filter_value: Option<&str>,
    ) -> crate::Result<()>;
}

/// Manages read-side RabbitMQ streams and live consumption.
#[async_trait]
pub trait ReadStreamBackend: Send + Sync {
    /// Returns true when the read stream already exists.
    async fn stream_exists<N: Namespace>(&self, namespace: &N) -> crate::Result<bool>;

    /// Create a read stream sized for the namespace's retention policy.
    async fn create_read_stream<N: Namespace>(
        &self,
        namespace: &N,
        max_event_bytes: u64,
    ) -> crate::Result<()>;

    /// Publish a versioned event to the read stream.
    async fn publish_to_stream(&self, event: &StreamEvent) -> crate::Result<()>;

    /// Publish a batch of historical events during stream bootstrap.
    async fn populate_stream(&self, events: &[StreamEvent]) -> crate::Result<()>;

    /// Subscribe to the live tail of a read stream.
    async fn subscribe_live<N: Namespace>(
        &self,
        namespace: &N,
        filter: Option<&StreamFilter>,
    ) -> crate::Result<impl Stream<Item = crate::Result<StreamEvent>> + Send>;
}