use std::{ borrow::Borrow, collections::HashMap, fmt::{Debug, Display, Formatter}, sync::{atomic::AtomicUsize, Arc}, }; use parking_lot::Mutex; use tokio::sync::mpsc; use crate::{ consumer::{Consumer, ConsumerId}, message::Message, newtype, newtype_id, ChannelId, }; pub type Queue = Arc; #[derive(Debug)] pub enum QueueEvent { PublishMessage(Message), Shutdown, } pub type QueueEventSender = mpsc::Sender; pub type QueueEventReceiver = mpsc::Receiver; newtype_id!(pub QueueId); newtype!( /// The name of a queue. A newtype wrapper around `Arc`, which guarantees cheap clones. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub QueueName: Arc ); impl Borrow for QueueName { fn borrow(&self) -> &str { std::borrow::Borrow::borrow(&self.0) } } impl Display for QueueName { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { Display::fmt(&self.0, f) } } #[derive(Debug)] pub struct QueueInner { pub id: QueueId, pub name: QueueName, pub messages: amqp_datastructure::MessageQueue, pub durable: bool, pub exclusive: Option, /// Whether the queue will automatically be deleted when no consumers uses it anymore. /// The queue can always be manually deleted. /// If auto-delete is enabled, it keeps track of the consumer count. pub deletion: QueueDeletion, pub consumers: Mutex>, pub event_send: QueueEventSender, } #[derive(Debug)] pub enum QueueDeletion { Auto(AtomicUsize), Manual, }