use super::entry::DlqEntry;
use super::error::DlqError;
#[non_exhaustive]
pub enum DlqBackend {
File(super::file::FileDlqInner),
#[cfg(feature = "dlq-kafka")]
Kafka(super::kafka::KafkaDlqInner),
#[cfg(feature = "dlq-http")]
Http(super::http::HttpDlqInner),
#[cfg(feature = "dlq-redis")]
Redis(super::redis_dlq::RedisDlqInner),
}
impl std::fmt::Debug for DlqBackend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("DlqBackend::")?;
f.write_str(self.name())
}
}
impl DlqBackend {
pub async fn send_batch(&mut self, batch: &[DlqEntry]) -> Result<(), DlqError> {
match self {
Self::File(b) => b.send_batch(batch).await,
#[cfg(feature = "dlq-kafka")]
Self::Kafka(b) => b.send_batch(batch).await,
#[cfg(feature = "dlq-http")]
Self::Http(b) => b.send_batch(batch).await,
#[cfg(feature = "dlq-redis")]
Self::Redis(b) => b.send_batch(batch).await,
}
}
#[must_use]
pub fn name(&self) -> &'static str {
match self {
Self::File(_) => "file",
#[cfg(feature = "dlq-kafka")]
Self::Kafka(_) => "kafka",
#[cfg(feature = "dlq-http")]
Self::Http(_) => "http",
#[cfg(feature = "dlq-redis")]
Self::Redis(_) => "redis",
}
}
}