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

What happens if exceptions are thrown in callbacks? #575

Closed
inad9300 opened this issue Jun 1, 2023 · 4 comments
Closed

What happens if exceptions are thrown in callbacks? #575

inad9300 opened this issue Jun 1, 2023 · 4 comments
Labels

Comments

@inad9300
Copy link

inad9300 commented Jun 1, 2023

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.

@pglombardo
Copy link
Contributor

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.

@inad9300
Copy link
Author

inad9300 commented Jun 1, 2023

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.");
})

@rod2j
Copy link

rod2j commented Jun 25, 2023

Encountered the same problem and would very much like this to be fixed.

@pglombardo
Copy link
Contributor

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.

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

No branches or pull requests

3 participants