英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论