AtherEnergy / rumqtt

Pure rust mqtt cilent
The Unlicense
202 stars 71 forks source link

How to get the topic name in new API #155

Closed opensourcegeek closed 5 years ago

opensourcegeek commented 5 years ago

I'm looking to get the topic name from notification and I'm not sure how to get it. In previous API, I used to be able to pass a MqttCallback which takes in a closure that gets called for each message. That message type had topic name and now it seems like I just get the cross beam channel as receiver, I'm not sure how to get the topic name from the notification. Any idea what API method I should use?

opensourcegeek commented 5 years ago

Does anyone know how to get the topic name?

tekjar commented 5 years ago

Topic name on acks or topic name of incoming publishes?

opensourcegeek commented 5 years ago

It's for incoming publishes.

tekjar commented 5 years ago

You receive a notification type and Publish has topic_name variable

for notification in notifications {
        if let Notification::Publish(p) = notification {
            println!("{:?}", p.topic_name);
        }
}
opensourcegeek commented 5 years ago

Thanks @tekjar, I didn't see that method in docs. I'll go through source and see where that property is getting set.

tekjar commented 5 years ago

Ok. Please close this once you got what you need