AtherEnergy / rumqtt

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

Example of publishing from a callback. #65

Closed glennpierce closed 6 years ago

glennpierce commented 6 years ago

Hi

The title says it all really. Is there a way I can publish from a callback. How could I pass the request object ?

Thanks

nanomad commented 6 years ago

Assuming I understood the question correctly, I found the tokio2 branch much nicer to work with API-wise

Here's a simple PING-PONG example https://gist.github.com/nanomad/1b1b9fca57b37737949fd5e1a9d3c6aa

Note that I'm publishing the reply messages in a different thread as it is a bad idea to delay the MQTT messages dequeuing (the for m in rx loop)

glennpierce commented 6 years ago

Thanks. I didn't know about the Tokio2 branch. I will look at your example. Basically all I want todo is to subscribe to electrical current readings from a number of energy monitors I have. On each new current reading I want to publish the power and energy.

nanomad commented 6 years ago

Yeah that's basically my use case as well. You can even remove the outer thread from my example as it is pointless for something very basic (it was a quick adaptation from my code)

tekjar commented 6 years ago

Thanks @nanomad for explaining this.