mirror of
https://github.com/csehviktor/status-monitor.git
synced 2025-08-08 18:06:14 +02:00
36 lines
853 B
Rust
36 lines
853 B
Rust
use broker::manager::MqttBroker;
|
|
use config::load_config;
|
|
use server::Server;
|
|
use std::sync::Arc;
|
|
use storage::{StorageRepositoryImpl, StorageStrategy};
|
|
|
|
pub mod bridge;
|
|
pub mod broker;
|
|
pub mod config;
|
|
pub mod server;
|
|
pub mod storage;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let cfg = load_config()?;
|
|
|
|
let storage = Arc::new(if cfg.storage.sqlite {
|
|
StorageRepositoryImpl::new(StorageStrategy::SQLite(format!(
|
|
"{}agents.db",
|
|
cfg.storage.db_path
|
|
)))
|
|
} else {
|
|
StorageRepositoryImpl::new(StorageStrategy::InMemory)
|
|
});
|
|
|
|
let broker = MqttBroker::new(cfg.mqtt, Arc::clone(&storage)).await;
|
|
let server = Server::new(broker.clients(), Arc::clone(&storage));
|
|
|
|
tokio::select! {
|
|
res = broker.run() => res?,
|
|
res = server.serve() => res,
|
|
}
|
|
|
|
Ok(())
|
|
}
|