Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Mosquitto » Is it permitted to publish in message callback?(Unsuccessfully publishing within message callback.)
Is it permitted to publish in message callback? [message #1815731] Wed, 09 October 2019 10:48 Go to next message
Liam Fry is currently offline Liam FryFriend
Messages: 3
Registered: October 2019
Junior Member
Is it possible to publish a message while inside the message callback?
I'm developing in C and using Mosquitto 1.6.7

I'm working on an application that, on occasion, has the need to publish while inside the message callback. However, all such publications fail silently.
Re: Is it permitted to publish in message callback? [message #1815766 is a reply to message #1815731] Thu, 10 October 2019 07:47 Go to previous messageGo to next message
Liam Fry is currently offline Liam FryFriend
Messages: 3
Registered: October 2019
Junior Member
As it turns out, yes, you can publish while inside the message handler.
After much trial and error, I found a solution but not the cause.
The solution: I had to raise my QoS from 0 to 1 on both publish and subscribe. If I don't raise the QoS, in my situation, I found that 97.2% of all "published while in message handler" messages were never delivered. Once QoS was raised to 1, delivery rate reached 100%. Unfortunately, raising the QoS to 1 has added an average of 800ms to message delivery time with approximately 12% of publications taking up to 3 seconds to be delivered.

UPDATE: I failed to note in my original post: all components - broker and my clients - are running on the same host. These times are stunningly bad and it does not bode well for when my application is released to the network.
I think it's worth noting that, when I alter my application in such a way as to move publications outside the message handler, delivery rate is fast and 100%, even with QoS at 0. Unfortunately, re-working my application so that no publications ever occur from within the message handler breaks functionality for which there is no easy solution at this time.
Re: Is it permitted to publish in message callback? [message #1815793 is a reply to message #1815766] Thu, 10 October 2019 20:43 Go to previous message
Roger Light is currently offline Roger LightFriend
Messages: 90
Registered: September 2013
Member
Can you provide any more details on how exactly you are doing things? Are you using mosquitto_loop(), mosquitto_loop_start(), or mosquitto_loop_forever()? Sending messages in a callback is absolutely fine, but you should not spend much time in the callback otherwise the network loop cannot run. It would be good to find out why it is that your messages are failing, I've not seen that sort of thing before.
Previous Topic:OnConnect() is not getting called.
Next Topic:monitor mosquitto requests connection established but no publish
Goto Forum:
  


Current Time: Fri Mar 29 00:06:08 GMT 2024

Powered by FUDForum. Page generated in 0.03331 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top