You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type of issue: improvement or how to, if the functionality doesn't exist already.
issue: in certain cases I'd be receiving a mqtt message, and in response I'll be updating the status of the request in multiple publishes to the same topic.
I feel instead of initializing the message via MessageBuilder, I'd like to update just the payload.
and use the same msg structure multiple sense.
Well, the cli.publish(msg) call takes ownership of the message, so we can't update the payload after that because the msg is no longer in scope.
The reason to "give" the message to the client for publishing , instead of passing a shared reference, is mostly for the async varieties of the client. When publish() returns, the operation has only been initiated and has not yet been completed. So the msg object couldn't be mutated since the client was still using it. Passing ownership of the message into the client solves this problem.
There is an alternate way to do what you want, though. Use the Topic struct. This is meant for your exact use case: when you want to repeatedly publish messages with different payloads to the same topic. Use it like:
let topic = mqtt::Topic::new(&cli, "test", QOS);
topic.publish("payload1");
topic.publish("payload2");
This does assume that cli is an AsyncClient. If you're using the synchronous Client, I suppose we can make a sync variety, or see if we can make it generic.
type of issue: improvement or how to, if the functionality doesn't exist already.
issue: in certain cases I'd be receiving a mqtt message, and in response I'll be updating the status of the request in multiple publishes to the same topic.
I feel instead of initializing the message via MessageBuilder, I'd like to update just the payload.
and use the same msg structure multiple sense.
current working:
proposed look:
The text was updated successfully, but these errors were encountered: