Vertx EventBus send() 和 request() 阻塞 WorkerVerticle

huangapple go评论60阅读模式
英文:

Vertx EventBus send() and request() blocking WorkerVerticle

问题

在WorkerVerticle的"start()"方法中,我运行EventBus上的"request()"或"send()"方法,它是阻塞的代码(我看到它不会执行下一行...)。

DeliveryOptions options = new DeliveryOptions().setSendTimeout(1000);
vertxEventBus.send("aaddress", "object", options);

我想处理这种情况:当"aaddress"的消费者不存在时,我希望vertxEventBus.send(...) / vertxEventBus.request(...)方法不会阻塞,而是抛出异常或在onFailure(...)上进行处理。代码应该继续执行下一行,而不会阻塞WorkerVerticle线程。在Vertx中是否有可能实现这一点?

英文:

I am trying to handle situation in Vertx when I have MainVerticle and WorkerVerticle (deployed from MainVerticle).
In 'start()' method of WorkerVerticle I run request() or send() methods on EventBus and it is a blocking code (I see that it doesn't go the next line...).

DeliveryOptions options = new DeliveryOptions().setSendTimeout(1000);
vertxEventBus.send("aaddress", "object", options);

I would like to handle situation when the consumer for "aaddress" doesn't exist - in this case I would like the vertxEventBus.send(...)/vertxEventBus.request(...) methods to not be blocking but throw some exception or be handled on onFailure(...). The code should 'go' to the next line and block the WorkerVerticle thread. Is it possible in Vertx?

答案1

得分: 1

我犯了一个愚蠢的错误,IntelliJ在调试时没有提供帮助。vertxEventBus为空,所以它不起作用。然而,我不明白为什么IntelliJ没有为我的代码发布NullPointerException的堆栈跟踪,而是整个单元测试在没有可见异常的情况下运行。在我正确初始化vertxEventBus之后,代码开始正常工作。

英文:

I made a stupid mistake and IntelliJ was not helpful in debugging. vertxEventBus was null so it didn't work. However I do not understand why IntelliJ didn't post stack trace with NullPointerException for my code, instead the whole unit test was run without any visible exception.
After I initialized vertxEventBus correctly the code started to work normally.

huangapple
  • 本文由 发表于 2023年4月17日 22:16:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定