Align MQTT endpoint with the command rfc
@@ -14,6 +14,9 @@ use ntex_mqtt::{
};
use std::fmt::Debug;
+const TOPIC_COMMAND_INBOX: &str = "command/inbox";
+const TOPIC_COMMAND_OUTBOX: &str = "command/outbox";
+
macro_rules! connect {
($connect:expr, $app:expr, $certs:expr) => {{
log::info!("new connection: {:?}", $connect);
@@ -146,14 +149,14 @@ pub async fn publish_v5(
macro_rules! subscribe {
($s: expr, $session: expr, $fail: expr) => {{
$s.iter_mut().for_each(|mut sub| {
- if sub.topic() == "command" {
+ if sub.topic() == TOPIC_COMMAND_INBOX {
let device_id = $session.state().device_id.clone();
let mut rx = $session.state().commands.subscribe(device_id.clone());
let sink = $session.sink().clone();
ntex::rt::spawn(async move {
while let Some(cmd) = rx.recv().await {
match sink
- .publish(ByteString::from_static("cmd"), Bytes::from(cmd.command))
+ .publish(ByteString::from(format!("{}/{}", TOPIC_COMMAND_OUTBOX, cmd.command)), Bytes::from(cmd.payload.unwrap()))
.send_at_least_once()
.await
{
