rabbit_auto/
config.rs

1//! Configuration for the rabbitmq connection.
2//!
3//!
4use std::fmt::Display;
5use std::sync::Arc;
6use std::time::Duration;
7use executor_trait::FullExecutor;
8use reactor_trait::Reactor;
9
10/// Configuration for the rabbitmq connection
11pub struct Config<E, R>
12where
13    E: FullExecutor,
14    R: Reactor,
15{
16    pub name: String,
17    pub address: Vec<String>,
18    pub reconnect_delay: Duration,
19    pub executor: Arc<E>,
20    pub reactor: Arc<R>,
21}
22
23impl<E, R> Config<E, R>
24    where
25        E: FullExecutor,
26        R: Reactor,
27{
28    /// Creates a new configuration
29    /// # Arguments:
30    /// * host - the address to rabbitmq server
31    /// * user - user login name
32    /// * password - user login password
33    /// * sleep_duration - duration of the sleep before trying reconnect again to the rabbitmq server
34    pub fn new<I: Display, T: Iterator<Item = I>>(
35        name: String,
36        host: T,
37        user: &str,
38        password: &str,
39        reconnect_delay: Duration,
40        executor: E,
41        reactor: R,
42    ) -> Self {
43        let mut address = Vec::new();
44        for addr in host {
45            let addr = format!("amqp://{}:{}@{}/%2f", user, password, addr);
46            address.push(addr);
47        }
48        Self {
49            name,
50            address,
51            reconnect_delay,
52            executor: Arc::new(executor),
53            reactor: Arc::new(reactor),
54        }
55    }
56}