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
//! # Crosstown Bus
//!
//! `crosstown_bus` is an easy-to-configure bus in Rust with RabbitMQ for event-driven systems.
pub mod tools;
mod bus;
mod message_handler;
mod common;

use std::{error::Error, cell::RefCell};

use amiquip::Connection;
use bus::{Publisher, Subscriber};
pub use common::QueueProperties;
pub use message_handler::MessageHandler;
pub use message_handler::HandleError;

pub struct CrosstownBus();

impl CrosstownBus {
    pub fn new_subscriber(url: String) -> Result<Subscriber, Box<dyn Error>> {
        Ok(Subscriber {
            cnn: RefCell::new(Connection::insecure_open(&url)?)
        })
    }
    
    pub fn new_publisher(url: String) -> Result<Publisher, Box<dyn Error>> {
        Ok(Publisher {
            cnn: RefCell::new(Connection::insecure_open(&url)?)
        })
    }
}