use std::{future::Future, sync::Arc, time::Duration};
use crate::{EventBusError, Message, PartialDeliveryState};
#[derive(Debug, Clone)]
pub struct ClaimedMessage {
pub id: String,
pub message: Arc<Message>,
pub state: PartialDeliveryState,
}
#[derive(Debug)]
pub enum FetchedEntry {
Decoded(ClaimedMessage),
Malformed { id: String, error: EventBusError },
}
pub trait StreamBackend: Send + Sync + 'static {
fn create_group(
&self,
stream: &str,
group: &str,
start_id: &str,
) -> impl Future<Output = Result<(), EventBusError>> + Send;
fn publish(
&self,
stream: &str,
message: Message,
) -> impl Future<Output = Result<String, EventBusError>> + Send;
fn reclaim_idle(
&self,
stream: &str,
group: &str,
consumer: &str,
min_idle: Duration,
count: usize,
) -> impl Future<Output = Result<Vec<FetchedEntry>, EventBusError>> + Send;
fn read_new(
&self,
stream: &str,
group: &str,
consumer: &str,
count: usize,
timeout: Duration,
) -> impl Future<Output = Result<Vec<FetchedEntry>, EventBusError>> + Send;
fn ack(
&self,
stream: &str,
group: &str,
message_id: &str,
) -> impl Future<Output = Result<(), EventBusError>> + Send;
fn ack_many(
&self,
stream: &str,
group: &str,
message_ids: &[String],
) -> impl Future<Output = Result<(), EventBusError>> + Send {
async move {
for id in message_ids {
self.ack(stream, group, id).await?;
}
Ok(())
}
}
#[allow(unused_variables)]
fn forget_consumer(
&self,
stream: &str,
group: &str,
consumer: &str,
) -> impl Future<Output = ()> + Send {
async {}
}
}
pub(crate) type SharedBackend<B> = Arc<B>;