Skip to content

Commit ed6e1c9

Browse files
committed
get topic from message and update template
Signed-off-by: karthik2804 <[email protected]>
1 parent c07fa80 commit ed6e1c9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ impl MqttTrigger {
206206
Ok(Some(msg)) => {
207207
// Handle the received message
208208
_ = self
209-
.handle_mqtt_event(&component_id, msg.payload().to_vec(), topic.clone())
209+
.handle_mqtt_event(
210+
&component_id,
211+
msg.payload().to_vec(),
212+
msg.topic().to_owned(),
213+
)
210214
.await
211215
.map_err(|err| tracing::error!("{err}"));
212216
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use spin_mqtt_sdk::{mqtt_component, Payload};
21
use chrono::{DateTime, Utc};
2+
use spin_mqtt_sdk::{mqtt_component, Metadata, Payload};
33

44
#[mqtt_component]
5-
fn handle_message(message: Payload) -> anyhow::Result<()> {
5+
async fn handle_message(message: Payload, metadata: Metadata) -> anyhow::Result<()> {
66
let datetime: DateTime<Utc> = std::time::SystemTime::now().into();
77
let formatted_time = datetime.format("%Y-%m-%d %H:%M:%S.%f").to_string();
88

@@ -12,4 +12,4 @@ fn handle_message(message: Payload) -> anyhow::Result<()> {
1212
String::from_utf8_lossy(&message)
1313
);
1414
Ok(())
15-
}
15+
}

0 commit comments

Comments
 (0)