Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: will callback block message sending through mosquitto_publish? #2655

Open
Keynib opened this issue Oct 12, 2022 · 2 comments
Open

Comments

@Keynib
Copy link

Keynib commented Oct 12, 2022

Hi! I'm developing a network application which has the following structure:

  • Listener thread, which calls mosquitto_loop_start and mosquitto_message_callback_set to work with input messages and answer some information by mosquitto_publish.
  • Publishing thread, which sends some information to MQTT topic by mosquitto_publish every minute.

The callback which is called when a listener thread receives a message processes the request, and this processing can take some time, let's say 30 seconds. Will this callback block work of publishing thread? For example, callback is processing the request right now. At this moment, publishing thread calls mosquitto_publish to send its message. Will this message be sent immediately or only after returning of listener callback?

P.S. This question is important to create a proper architecture. I want to understand that do I need to create one more thread, which will be used as message processor and will receive information from listener thread by some IPC to free callback from request processing, and it will return as fast as possibly to don't block publishing thread. Or I am wrong and callback from mosquitto_message_callback_set doesn't block mosquitto_publish call, the message will be sent without delays and it's unimportant how much time the callback works with request.

P.S.S. Is it correct behavior to process request inside the callback? Or it's better to give request processing to another thread and free callback work faster? Maybe two-threads will increase the application speed somehow, but I'm not pretty sure, because request processing is single-thread anyway, It depends on libmosquitto internal work and I want to understand that will callback block mosquitto message receving, sending and so on or not.

@Keynib
Copy link
Author

Keynib commented Feb 10, 2023

Any updates?

@technoshamanarchist
Copy link

technoshamanarchist commented Apr 30, 2024

I'm not very experienced with Mosquitto, but currently I'm having a problem if the callback is waiting for a response (a flag), and if I'm also trying to publish during this time. I'm also looking for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants