mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-29 00:27:35 +02:00
use cli parser for agent
This commit is contained in:
+4
-6
@@ -3,17 +3,15 @@ use rumqttc::{AsyncClient, MqttOptions, QoS};
|
||||
use std::time::Duration;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::config::MqttConfig;
|
||||
|
||||
pub struct MqttHandle {
|
||||
pub agent: &'static str,
|
||||
pub agent: String,
|
||||
pub client: AsyncClient,
|
||||
pub eventloop_handle: JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl MqttHandle {
|
||||
pub async fn create(cfg: &'static MqttConfig) -> Self {
|
||||
let mut mqttoptions = MqttOptions::new(&cfg.agent, &cfg.host, cfg.port);
|
||||
pub async fn create(agent: String, host: String, port: u16) -> Self {
|
||||
let mut mqttoptions = MqttOptions::new(&agent, &host, port);
|
||||
mqttoptions.set_keep_alive(Duration::from_secs(5));
|
||||
|
||||
let (client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
|
||||
@@ -28,7 +26,7 @@ impl MqttHandle {
|
||||
});
|
||||
|
||||
Self {
|
||||
agent: &cfg.agent,
|
||||
agent,
|
||||
client,
|
||||
eventloop_handle
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user