pub trait MessageQueue: Send + Sync {
// Required methods
fn push<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
msg: WeixinMessage,
) -> Pin<Box<dyn Future<Output = Result<bool, HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn drain<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<WeixinMessage>, HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn wait_notify<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
timeout_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn remove_client<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn queue_sizes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, usize>, HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn push_shared<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
base: Arc<WeixinMessage>,
context_token: Option<String>,
hub_ext: Option<HubExt>,
) -> Pin<Box<dyn Future<Output = Result<bool, HubError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Abstraction over a message queue backend for iLink Hub.
§Object Safety
This trait is object-safe and intended to be used as Arc<dyn MessageQueue>.
§Downstream Crate Integration
Downstream crates can implement this trait for custom backends (e.g. Redis)
and inject them into crate::hub::HubState:
use ilink_hub::MessageQueue;
use ilink_hub::hub::HubState;
use ilink_hub::error::HubError;
use ilink_hub::ilink::types::WeixinMessage;
use async_trait::async_trait;
use std::collections::HashMap;
use std::sync::Arc;
struct CustomQueue;
#[async_trait]
impl MessageQueue for CustomQueue {
async fn push(&self, _vtoken: &str, _msg: WeixinMessage) -> Result<bool, HubError> {
Ok(false)
}
async fn drain(&self, _vtoken: &str) -> Result<Vec<WeixinMessage>, HubError> {
Ok(vec![])
}
async fn wait_notify(&self, _vtoken: &str, _timeout_secs: u64) -> Result<bool, HubError> {
Ok(false)
}
async fn remove_client(&self, _vtoken: &str) -> Result<(), HubError> {
Ok(())
}
async fn queue_sizes(&self) -> Result<HashMap<String, usize>, HubError> {
Ok(HashMap::new())
}
}Required Methods§
fn push<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
msg: WeixinMessage,
) -> Pin<Box<dyn Future<Output = Result<bool, HubError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn drain<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<WeixinMessage>, HubError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wait_notify<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
timeout_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, HubError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove_client<'life0, 'life1, 'async_trait>(
&'life0 self,
vtoken: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), HubError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn queue_sizes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, usize>, HubError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Provided Methods§
Optimised push for the broadcast path: the base message is shared via
Arc<WeixinMessage> and only the per-recipient context_token and
ilink_hub_ext are supplied separately. The base clone cost drops from
O(N × msg_size) to O(msg_size) + N × cheap field clone, which matters
when many backends are online and a message carries images / files.
The default implementation clones the base and overlays the overrides, so implementations that don’t care about the optimisation still work.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".