-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
402 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
##-------------------------------------------------------------------- | ||
## rmqtt-sys-topic | ||
##-------------------------------------------------------------------- | ||
|
||
#$SYS system message publish QoS | ||
publish_qos = 1 | ||
|
||
#$SYS system message publish period | ||
publish_interval = "1m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "rmqtt-sys-topic" | ||
version = "0.1.0" | ||
authors = ["rmqtt <rmqttd@126.com>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rmqtt = "0.2" | ||
serde = { version = "1.0", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use serde::de::{self, Deserialize, Deserializer}; | ||
use std::time::Duration; | ||
|
||
use rmqtt::broker::types::QoS; | ||
use rmqtt::serde_json; | ||
use rmqtt::settings::to_duration; | ||
use rmqtt::Result; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct PluginConfig { | ||
#[serde( | ||
default = "PluginConfig::publish_qos_default", | ||
deserialize_with = "PluginConfig::deserialize_publish_qos" | ||
)] | ||
pub publish_qos: QoS, | ||
|
||
#[serde( | ||
default = "PluginConfig::publish_interval_default", | ||
deserialize_with = "PluginConfig::deserialize_publish_interval" | ||
)] | ||
pub publish_interval: Duration, | ||
} | ||
|
||
impl PluginConfig { | ||
#[inline] | ||
fn publish_qos_default() -> QoS { | ||
QoS::AtLeastOnce | ||
} | ||
|
||
#[inline] | ||
fn publish_interval_default() -> Duration { | ||
Duration::from_secs(60) | ||
} | ||
|
||
#[inline] | ||
pub fn to_json(&self) -> Result<serde_json::Value> { | ||
Ok(serde_json::to_value(self)?) | ||
} | ||
|
||
#[inline] | ||
fn deserialize_publish_qos<'de, D>(deserializer: D) -> Result<QoS, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let qos = match u8::deserialize(deserializer)? { | ||
0 => QoS::AtMostOnce, | ||
1 => QoS::AtLeastOnce, | ||
2 => QoS::ExactlyOnce, | ||
_ => return Err(de::Error::custom("QoS configuration error, only values (0,1,2) are supported")), | ||
}; | ||
Ok(qos) | ||
} | ||
|
||
#[inline] | ||
pub fn deserialize_publish_interval<'de, D>(deserializer: D) -> Result<Duration, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let v = String::deserialize(deserializer)?; | ||
let d = to_duration(&v); | ||
if d < Duration::from_secs(1) { | ||
Err(de::Error::custom("'publish_interval' must be greater than 1 second")) | ||
} else { | ||
Ok(d) | ||
} | ||
} | ||
} |
Oops, something went wrong.