拥有一个消息驱动的 bean“fire”;作为两个事件的结果?

发布于 2024-11-25 11:11:18 字数 412 浏览 3 评论 0原文

我希望 MDB 仅在到达两个独立国家后才启动。例如:

事件A发生 一段时间过去了 事件B发生 A 事件和 B 事件同时发生时调用 MDB onMessage A 和 B 事件被清除

因此,例如,如果事件 B 发生但事件 A 尚未发生,那么我不希望触发 onMessage。同样,如果事件 A 发生但事件 B 未发生,我不希望 onMessage 触发。我还希望事件 A 和 B 相关联,以便在触发 onMessage 时事件 A 和 B 被清除。

实现此目的的一种方法是让事件 A 生成一条消息,该消息处理程序将检查事件 B 是否已发生,但它必须阻塞并循环,直到事件 B 触发为止。轮询方案似乎效率低下。

从功能上讲,这类似于 CyclicBarrier,但通过消息传递实现。

对于 MDB 是否可以实现这样的事情,有什么想法吗?

I would like to have an MDB that fires only after two independent states have been reached. For example:

Event A occurs
some time passes
Event B occurs
MDB onMessage is called as a result of both A and B event occurring
A and B events are cleared

So for example if Event B occurs but Event A has not occurred then I do not want the onMessage triggered. Similarly if Event A occurs but Event B has not occurred I do not want the onMessage to fire. I also want Event A and B to be correlated such that when onMessage is fired Events A and B are cleared.

One way to do this would be to have Event A produce a message and the message handler for that would check to see if Event B has occurred but it would have to block and loop until an Event B had fired. The polling scheme seems inefficient.

Functionally this would act like a CyclicBarrier but implemented with messaging.

Any thoughts as to whether or not something like this is possible with MDBs?

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

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

发布评论

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

评论(1

辞慾 2024-12-02 11:11:18

对此没有内置机制。我建议将增量状态存储在数据库表中(收到第一个事件时插入,收到第二个事件时更新/删除)。

我绝对不建议投票;有太多的事情可能会出错(服务器线程挂起、CPU 浪费、事务超时等)。

There is no builtin mechanism for this. I would recommend storing incremental state in a DB table (insert when the first event is received, update/delete when the second event is received).

I would definitely not recommend polling; there are far too many things that can go wrong (hung server threads, wasted CPU, transaction timeouts, etc.).

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