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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! In-memory message broker implementation
//!
//! This module provides a high-performance, thread-safe in-memory message broker
//! that implements the Publisher and Subscriber traits. It's designed for testing,
//! development, and scenarios where external message brokers are not required.
//!
//! # Features
//!
//! - Thread-safe concurrent access
//! - Configurable queue size limits
//! - Topic management with subscriber broadcasting
//! - Optional statistics collection
//! - Message ordering guarantees
//! - Graceful shutdown support
//! - Publisher and Subscriber trait implementations
//!
//! # Example
//!
//! ```rust,no_run
//! use kincir::memory::{InMemoryBroker, InMemoryConfig, InMemoryPublisher, InMemorySubscriber};
//! use kincir::{Publisher, Subscriber, Message};
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create broker with custom configuration
//! let config = InMemoryConfig::new()
//! .with_max_queue_size(Some(1000))
//! .with_stats(true);
//!
//! let broker = Arc::new(InMemoryBroker::new(config));
//!
//! // Create publisher and subscriber
//! let publisher = InMemoryPublisher::new(broker.clone());
//! let mut subscriber = InMemorySubscriber::new(broker.clone());
//!
//! // Subscribe to a topic
//! subscriber.subscribe("my-topic").await?;
//!
//! // Publish messages
//! let messages = vec![
//! Message::new(b"Hello".to_vec()),
//! Message::new(b"World".to_vec()),
//! ];
//! publisher.publish("my-topic", messages).await?;
//!
//! // Receive messages
//! let message1 = subscriber.receive().await?;
//! let message2 = subscriber.receive().await?;
//!
//! println!("Received: {:?}", String::from_utf8_lossy(&message1.payload));
//! println!("Received: {:?}", String::from_utf8_lossy(&message2.payload));
//!
//! Ok(())
//! }
//! ```
// Fixed acknowledgment implementation
// Re-export public types
pub use ;
pub use ; // Export fixed types
pub use ;
pub use InMemoryConfig;
pub use InMemoryError;
pub use InMemoryPublisher;
pub use ;
pub use InMemorySubscriber;