2

对于如何使用 EventBus 在 Reactor (2.X) 中完成此用例的任何建议,我将不胜感激

主线程使用 threadPoolExecutor 将事件分派到主题“foo”。该事件可能会发送给一些订阅了“foo”的消费者。这些消费者检查事件数据并确定是否存在问题。

我希望主线程暂停并等待满足其中一个条件:

  1. 所有消费者都收到事件,完成运行并且没有发现任何问题。主线程恢复执行
  2. 一位消费者发现问题,主线程应该抛出异常
  3. 其中一个消费者运行时间过长,主线程应恢复执行但记录警告

所以像

// dispatch event to all consumers
notify("foo", event);
// wait on all consumers to either finish or timeout after 100 ms
// consumers are running on X separate threads, doing their analysis
boolean anyErrors = waitOnConsumers(100);
if(anyErrors){
    throw new BlockedExecutionException("A problem occurred");
}
4

0 回答 0