we have a python microservice handling the MQTT integration between the devices and Cumulocity, Part of this python code is to receive the external ID from the device and to ask cumulocity API for its corresponding internal ID, the issue is that a small number of devices are still not added by admin on Cumulocity side which should not be an issue since this part is included in a try/except
but practically after seeing this, the code becomes hanging and no new messages are received via MQTT, any hint to overcome this?
Without knowing the code snippet it’s hard to debug but I would assume your are not handling the exception correctly which in the ends lead to that the thread is blocked/exited which is also mainly responsible to receive new messages.
So it’s a combination of threading and error handling I would assume.
As this is a microservice I would suggest to improve your threading logic e.g. try to do stuff async and keep the “on_messsage” Thread available. Also make sure you properly handle the exceptions so no thread is exited unexpectedly.
Again, this is just a remote analysis. The real issue could be also something else of course.
Hi Stefan, I have shared the python code via a message. what do you suggest as a way to handle the exception correctly?
additionally right now we still did not implement multi-treading so most probably we will need this when having a higher volume of MQTT messages coming in. Is it what is recommended when you mentioned that “try to do stuff async and keep the “on_messsage” Thread available”?
any other recommendation to improve the stability and performance of this python code is appreciated, thanks,
As figured out via PM: It most probably relates to that the subscribe was not in on_connect handler but in sequence to it, leading to the fact that once the connection is broken, re-connection is happening but no re-subscribe causing that no additional messages are received.