微米计时器异常处理

发布于 2025-01-26 06:44:16 字数 210 浏览 3 评论 0原文

我想处理记录的方法中引发的异常。例如,我将消息发送给Kafka,方法kafka.send(),我记录了它:timer.record(() - > kafka.send())> Kafka可能会产生一些例外,如果发生这种情况,我想进行某种交易并回滚一些代码。如何处理在kafka中抛出的异常。正如我在计时器守则中看到的那样,吞咽异常,对吗?

I want to handle exception thrown in method which is recorded. For example, I send message to kafka with method kafka.send(), I record it: timer.record(() -> kafka.send())
Kafka may produce some exception and if its happened, I want to make some kind of transaction and rollback some code. How can I handle exception thrown in kafka.send method? As I saw in code of timer.record, it swallows exception, is it right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2025-02-02 06:44:16

No, timer.record method doesn't swallow the exception. There is only finally-block, but no catch-block: https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java

And you can handle the exception in your code as usual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文