pub trait MessageQueue: Send + Sync {
// Required methods
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 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 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 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;
// Provided methods
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 { ... }
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 { ... }
}Expand description
消息队列统一抽象
提供发布/消费/确认/订阅四个核心方法, 以及 nack(重试)和 reject(死信)两个扩展方法(带默认实现,向后兼容)。
Required Methods§
Sourcefn 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
Sourcefn 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 状态)
Provided Methods§
Sourcefn 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,
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,
消息重回队列尾部(带重试次数追踪)
- 将消息从 in_flight 移回原 topic 队列尾部,retry_count + 1
- 当 retry_count 达到 max_retries 时自动转入死信队列
默认实现返回 NotSupported 错误(保持向后兼容)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".