1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Broker implementations and trait abstractions for message publishing and subscription.
//!
//! This module provides a pluggable architecture for interacting with different message brokers
//! while maintaining a consistent API. It defines core traits that enable broker-agnostic code,
//! along with concrete implementations for popular brokers like NATS and Redis.
//!
//! # Core Traits
//!
//! The module exports two primary traits that form the foundation of the broker abstraction:
//!
//! - [`PubBrokerTrait`]: Provides methods to publish raw byte payloads to a topic.
//! - [`SubBrokerTrait`]: Provides methods to subscribe to a topic and receive a stream
//! of messages with acknowledgment handles.
//!
//! These traits enable you to write broker-agnostic code and swap implementations at runtime.
//!
//! # Available Implementations
//!
//! - [`nats`]: NATS JetStream broker implementation for high-performance message streaming.
//! - [`redis`]: Redis Streams broker implementation for persistent message queuing.
//!
//! # Error Handling
//!
//! The [`errors`] submodule provides broker-specific and common error types that may be
//! returned by broker operations.
//!
//! # Example
//!
//! ```rust
//! use std::sync::Arc;
//! use object_transfer::brokers::{PubBrokerTrait, SubBrokerTrait};
//!
//! async fn example(
//! pub_broker: Arc<dyn PubBrokerTrait>,
//! sub_broker: Arc<dyn SubBrokerTrait>,
//! ) -> Result<(), Box<dyn std::error::Error>> {
//! // Publish a message
//! pub_broker.publish("topic", bytes::Bytes::from("message")).await?;
//!
//! // Subscribe to messages
//! let mut stream = sub_broker.subscribe().await?;
//!
//! // Handle incoming messages
//! while let Some(result) = futures::stream::StreamExt::next(&mut stream).await {
//! match result {
//! Ok((payload, ack)) => {
//! // Process payload
//! ack.ack().await?;
//! }
//! Err(e) => eprintln!("Error receiving message: {}", e),
//! }
//! }
//!
//! Ok(())
//! }
//! ```
pub use ;