use lapin::ExchangeKind;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RabbitExchange {
name: String,
kind: ExchangeKind,
durable: bool,
auto_delete: bool,
}
impl RabbitExchange {
fn new(name: impl Into<String>, kind: ExchangeKind) -> Self {
Self {
name: name.into(),
kind,
durable: true,
auto_delete: false,
}
}
#[must_use]
pub fn direct(name: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Direct)
}
#[must_use]
pub fn topic(name: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Topic)
}
#[must_use]
pub fn fanout(name: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Fanout)
}
#[must_use]
pub fn headers(name: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Headers)
}
#[must_use]
pub fn custom(name: impl Into<String>, kind: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Custom(kind.into()))
}
#[cfg(feature = "plugin-consistent-hash")]
#[must_use]
pub fn consistent_hash(name: impl Into<String>) -> Self {
Self::new(name, ExchangeKind::Custom("x-consistent-hash".to_owned()))
}
#[must_use]
pub fn durable(mut self, durable: bool) -> Self {
self.durable = durable;
self
}
#[must_use]
pub fn auto_delete(mut self, auto_delete: bool) -> Self {
self.auto_delete = auto_delete;
self
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
pub(crate) fn kind(&self) -> &ExchangeKind {
&self.kind
}
pub(crate) fn is_durable(&self) -> bool {
self.durable
}
pub(crate) fn is_auto_delete(&self) -> bool {
self.auto_delete
}
}