azums_core/backend/
stream.rs1use crate::{
2 backend::NotificationStream,
3 model::{ConsumerGroupStatus, Event, NewEvent},
4};
5use async_trait::async_trait;
6
7#[async_trait]
9pub trait StreamBackend: Send + Sync {
10 async fn publish(&self, stream: &str, event: NewEvent) -> anyhow::Result<i64>;
12
13 async fn subscribe_stream(
15 &self,
16 stream: &str,
17 consumer_group: &str,
18 last_seq: Option<i64>,
19 ) -> anyhow::Result<NotificationStream>;
20
21 async fn ack(&self, stream: &str, consumer_group: &str, seq: i64) -> anyhow::Result<()>;
23
24 async fn read_events(
26 &self,
27 stream: &str,
28 after_seq: i64,
29 limit: i64,
30 ) -> anyhow::Result<Vec<Event>>;
31
32 async fn read_next(
34 &self,
35 stream: &str,
36 consumer_group: &str,
37 limit: i64,
38 ) -> anyhow::Result<Vec<Event>> {
39 let last_acked_seq = self
40 .consumer_group_info(stream)
41 .await?
42 .into_iter()
43 .find(|status| status.consumer_group == consumer_group)
44 .map(|status| status.last_acked_seq)
45 .unwrap_or(0);
46
47 self.read_events(stream, last_acked_seq, limit).await
48 }
49
50 async fn prune_events(&self, stream: &str, through_seq: i64) -> anyhow::Result<u64>;
55
56 async fn consumer_group_info(&self, stream: &str) -> anyhow::Result<Vec<ConsumerGroupStatus>>;
58}