1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use std::fmt::Debug; use crate::message::Delivery; #[derive(Debug)] pub struct Consumer { tag: String, no_local: bool, no_ack: bool, exclusive: bool, nowait: bool, subscriber: Box<dyn ConsumerSubscriber>, pub current_message: Option<Delivery>, } impl Consumer { pub fn new(tag: String, no_local: bool, no_ack: bool, exclusive: bool, nowait: bool, subscriber: Box<dyn ConsumerSubscriber>) -> Consumer { Consumer { tag, no_local, no_ack, exclusive, nowait, subscriber, current_message: None, } } pub fn new_delivery_complete(&mut self) { if let Some(delivery) = self.current_message.take() { self.subscriber.new_delivery(delivery); } } pub fn drop_prefetched_messages(&mut self) { self.subscriber.drop_prefetched_messages(); } pub fn cancel(&mut self) { self.subscriber.cancel(); } } pub trait ConsumerSubscriber: Debug+Send+Sync { fn new_delivery(&mut self, delivery: Delivery); fn drop_prefetched_messages(&mut self); fn cancel(&mut self); }