implement storage + improve code

This commit is contained in:
csehviktor
2025-07-06 02:28:29 +02:00
parent d2a82e973b
commit bf9d1e4da6
14 changed files with 357 additions and 62 deletions

View File

@@ -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");