mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-29 00:27:35 +02:00
implement storage + improve code
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
use rumqttd::{Broker, Config};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::bridge::ClientManager;
|
||||
use crate::{bridge::ClientManager, storage::StorageRepositoryImpl};
|
||||
use super::subscriber::MqttSubscriber;
|
||||
|
||||
pub struct MqttBroker {
|
||||
broker: &'static mut Broker,
|
||||
clients: Arc<ClientManager>,
|
||||
storage: Arc<StorageRepositoryImpl>,
|
||||
}
|
||||
|
||||
impl MqttBroker {
|
||||
pub async fn new(cfg: Config) -> Self {
|
||||
pub async fn new(cfg: Config, storage: Arc<StorageRepositoryImpl>) -> Self {
|
||||
let clients = Arc::new(ClientManager::new());
|
||||
let broker: &'static mut Broker = Box::leak(Box::new(Broker::new(cfg)));
|
||||
|
||||
Self {
|
||||
broker,
|
||||
clients,
|
||||
storage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ impl MqttBroker {
|
||||
}
|
||||
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
let mut subscriber = MqttSubscriber::new(&self.broker, self.clients);
|
||||
let mut subscriber = MqttSubscriber::new(&self.broker, self.clients, self.storage.inner());
|
||||
|
||||
println!("starting mqtt broker on specified port");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user