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
80
81
82
83
|
use std::env;
use std::error::Error;
use std::path::PathBuf;
use tracing::{error, info};
use tickborg::config;
use tickborg::easyamqp::{self, ChannelExt, ConsumerExt};
use tickborg::easylapin;
use tickborg::tasks;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
tickborg::setup_log();
let arg = env::args()
.nth(1)
.unwrap_or_else(|| panic!("usage: {} <config>", std::env::args().next().unwrap()));
let cfg = config::load(arg.as_ref());
let Some(collector_cfg) = config::load(arg.as_ref()).log_message_collector else {
error!("No log message collector configuration found!");
panic!();
};
let conn = easylapin::from_config(&collector_cfg.rabbitmq).await?;
let mut chan = conn.create_channel().await?;
chan.declare_exchange(easyamqp::ExchangeConfig {
exchange: "logs".to_owned(),
exchange_type: easyamqp::ExchangeType::Topic,
passive: false,
durable: true,
auto_delete: false,
no_wait: false,
internal: false,
})
.await?;
let queue_name = "logs".to_owned();
chan.declare_queue(easyamqp::QueueConfig {
queue: queue_name.clone(),
passive: false,
durable: false,
exclusive: true,
auto_delete: true,
no_wait: false,
})
.await?;
chan.bind_queue(easyamqp::BindQueueConfig {
queue: queue_name.clone(),
exchange: "logs".to_owned(),
routing_key: Some("*.*".to_owned()),
no_wait: false,
})
.await?;
// Regular channel, we want prefetching here.
let handle = chan
.consume(
tasks::log_message_collector::LogMessageCollector::new(
PathBuf::from(collector_cfg.logs_path),
100,
),
easyamqp::ConsumeConfig {
queue: queue_name.clone(),
consumer_tag: format!("{}-log-collector", cfg.whoami()),
no_local: false,
no_ack: false,
no_wait: false,
exclusive: false,
},
)
.await?;
info!("Fetching jobs from {}", &queue_name);
handle.await;
drop(conn); // Close connection.
info!("Closed the session... EOF");
Ok(())
}
|