pub struct InMemoryQueue { /* private fields */ }Implementations§
Source§impl InMemoryQueue
impl InMemoryQueue
pub fn new() -> Self
Sourcepub fn with_max_messages_per_topic(max: usize) -> Self
pub fn with_max_messages_per_topic(max: usize) -> Self
创建指定每 topic 最大消息数的队列(H-3 修复)
当队列中消息数达到此限制时,publish 将返回 MqError::Publish 错误。
默认 100,000,可根据内存容量调整。
Sourcepub fn with_max_retries(max_retries: u32) -> Self
pub fn with_max_retries(max_retries: u32) -> Self
创建指定最大重试次数的队列
max_retries = 3(默认):允许 3 次 nack 重试,第 3 次 nack 转入死信队列max_retries = 0:不允许重试,第一次 nack 即转入死信队列
Sourcepub fn with_backpressure(policy: BackpressurePolicy) -> Self
pub fn with_backpressure(policy: BackpressurePolicy) -> Self
创建带背压策略的队列
policy.max_queue_size 将同时设置 max_messages_per_topic,
确保背压策略与 H-3 限制一致。
pub async fn message_count(&self, topic: &str) -> usize
pub async fn subscriber_count(&self, topic: &str) -> usize
pub async fn in_flight_count(&self) -> usize
Sourcepub async fn dead_letter_count(&self, topic: &str) -> usize
pub async fn dead_letter_count(&self, topic: &str) -> usize
死信队列中的消息数(指定 topic)
如果 topic 不存在死信队列,返回 0。
Sourcepub async fn consume_dead_letter(&self, topic: &str) -> Option<Message>
pub async fn consume_dead_letter(&self, topic: &str) -> Option<Message>
消费一条死信消息(从死信队列头部弹出)
注意:此操作不会增加 in_flight 计数,死信消息不再走正常 ack 流程。
返回 None 表示该 topic 没有死信消息。
Trait Implementations§
Source§impl Clone for InMemoryQueue
impl Clone for InMemoryQueue
Source§impl Default for InMemoryQueue
impl Default for InMemoryQueue
Source§impl MessageQueue for InMemoryQueue
impl MessageQueue for InMemoryQueue
Source§fn publish<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
topic: &'life1 str,
message: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn publish<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
topic: &'life1 str,
message: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
发布消息到指定 topic
Source§fn consume<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>, MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn consume<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>, MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
从指定 topic 消费一条消息(消息进入 in_flight 状态)
Source§fn ack<'life0, 'life1, 'async_trait>(
&'life0 self,
message_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn ack<'life0, 'life1, 'async_trait>(
&'life0 self,
message_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
确认消息已处理完成(从 in_flight 移除)
Source§fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), MqError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
订阅 topic
Auto Trait Implementations§
impl !RefUnwindSafe for InMemoryQueue
impl !UnwindSafe for InMemoryQueue
impl Freeze for InMemoryQueue
impl Send for InMemoryQueue
impl Sync for InMemoryQueue
impl Unpin for InMemoryQueue
impl UnsafeUnpin for InMemoryQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more