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