Skip to main content

InMemoryQueue

Struct InMemoryQueue 

Source
pub struct InMemoryQueue { /* private fields */ }

Implementations§

Source§

impl InMemoryQueue

Source

pub fn new() -> Self

Source

pub fn with_max_messages_per_topic(max: usize) -> Self

创建指定每 topic 最大消息数的队列(H-3 修复)

当队列中消息数达到此限制时,publish 将返回 MqError::Publish 错误。 默认 100,000,可根据内存容量调整。

Source

pub fn with_max_retries(max_retries: u32) -> Self

创建指定最大重试次数的队列

  • max_retries = 3(默认):允许 3 次 nack 重试,第 3 次 nack 转入死信队列
  • max_retries = 0:不允许重试,第一次 nack 即转入死信队列
Source

pub fn with_backpressure(policy: BackpressurePolicy) -> Self

创建带背压策略的队列

policy.max_queue_size 将同时设置 max_messages_per_topic, 确保背压策略与 H-3 限制一致。

Source

pub async fn message_count(&self, topic: &str) -> usize

Source

pub async fn subscriber_count(&self, topic: &str) -> usize

Source

pub async fn in_flight_count(&self) -> usize

Source

pub async fn dead_letter_count(&self, topic: &str) -> usize

死信队列中的消息数(指定 topic)

如果 topic 不存在死信队列,返回 0。

Source

pub async fn consume_dead_letter(&self, topic: &str) -> Option<Message>

消费一条死信消息(从死信队列头部弹出)

注意:此操作不会增加 in_flight 计数,死信消息不再走正常 ack 流程。 返回 None 表示该 topic 没有死信消息。

Source

pub async fn requeue_dead_letter(&self, message_id: &str) -> Result<(), MqError>

将死信消息重新放回原 topic 队列(重置 retry_count = 0)

在所有 topic 的死信队列中查找指定 message_id。 找到后从死信队列移除,重置 retry_count,放回原 topic 队列尾部。

Trait Implementations§

Source§

impl Clone for InMemoryQueue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for InMemoryQueue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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,

发布消息到指定 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,

从指定 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,

确认消息已处理完成(从 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,

订阅 topic
Source§

fn nack<'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,

消息重回队列尾部(带重试次数追踪) Read more
Source§

fn reject<'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,

消息直接进入死信队列(不重试,不增加 retry_count) Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.