pub struct InMemoryBroker<T: Clone + Send + Sync + 'static> { /* private fields */ }Expand description
An in-memory message broker backed by a tokio::sync::broadcast channel.
Create one broker and hand out producers / consumers via
InMemoryBroker::producer and InMemoryBroker::consumer.
Every message sent through the broker is recorded in an internal history so that test assertion helpers can inspect what was published.
Implementations§
Source§impl<T: Clone + Send + Sync + 'static> InMemoryBroker<T>
impl<T: Clone + Send + Sync + 'static> InMemoryBroker<T>
Sourcepub fn producer(&self) -> InMemoryProducer<T>
pub fn producer(&self) -> InMemoryProducer<T>
Create a producer attached to this broker.
Sourcepub fn with_history_limit(capacity: usize, history_limit: usize) -> Self
pub fn with_history_limit(capacity: usize, history_limit: usize) -> Self
Create a broker with explicit channel capacity and bounded history limit.
The default InMemoryBroker::new bounds history by channel capacity. Use this
constructor when tests need a different history limit.
Sourcepub fn consumer(&self) -> InMemoryConsumer<T>
pub fn consumer(&self) -> InMemoryConsumer<T>
Create a consumer attached to this broker.
Sourcepub async fn messages(&self, topic: &str) -> Vec<Message<T>>
pub async fn messages(&self, topic: &str) -> Vec<Message<T>>
Return a clone of all messages published to topic.
Sourcepub async fn all_messages(&self) -> Vec<Message<T>>
pub async fn all_messages(&self) -> Vec<Message<T>>
Return a clone of every message published to any topic.
Sourcepub async fn message_count(&self, topic: &str) -> usize
pub async fn message_count(&self, topic: &str) -> usize
Return the number of messages published to topic.
Sourcepub async fn create_topic(&self, topic: &str)
pub async fn create_topic(&self, topic: &str)
Pre-create a topic so that it appears in InMemoryBroker::topic_names.
Sourcepub async fn topic_names(&self) -> Vec<String>
pub async fn topic_names(&self) -> Vec<String>
Return the sorted set of topic names that have been created or published to.
Trait Implementations§
Source§impl<T: Clone + Clone + Send + Sync + 'static> Clone for InMemoryBroker<T>
impl<T: Clone + Clone + Send + Sync + 'static> Clone for InMemoryBroker<T>
Source§fn clone(&self) -> InMemoryBroker<T>
fn clone(&self) -> InMemoryBroker<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more