hivemq-mqtt-client
hivemq-mqtt-client copied to clipboard
What happens if exceptions are thrown in callbacks?
I have a Mqtt5AsyncClient
on which I call subscribeWith()
, .callback()
, etc. My question is, what would happen if an exception is thrown by the consumer passed as callback? In my experiments, the consumer is never called again after such an event, so I would like to understand more in detail what happens internally in HiveMQ in case of exception, and what is the expectation from library users. I was quite surprised by this behavior to be honest – I was expecting HiveMQ to handle the exception in such a way that future calls to the callback kept working.
Hi @inad9300 - @SgtSilvio might know off hand as he's the original author. Do you have a test case? We could definitely document this better with our findings.
I guess it depends what you mean by test case. This is basically the code I used for my experiment:
.callback(__ -> {
System.out.println("Handling message..."); // Printed once and never again.
throw new RuntimeException("Error handling message.");
})
Encountered the same problem and would very much like this to be fixed.
Hi @inad9300 @rod2j, the current requirement is to protect against exceptions in callbacks but this could be improved and definitely at least documented.
I filed #624 to improve this behaviour based on your suggestions. If you have any other suggestions or ideas, feel free to add them into #624.
I'll close this question issue for now. If anything else remains, let me know.