Java 中的轻量级消息传递(异步调用)

发布于 2024-07-08 00:23:37 字数 383 浏览 6 评论 0原文

我正在寻找 Java 中的轻量级消息传递框架。 我的任务是以 SEDA 的方式处理事件:我知道处理的某些阶段可以快速完成,而其他阶段则不能,并且希望解耦这些处理阶段。

假设我有组件 A 和 B,处理引擎(无论是这个容器还是其他容器)调用组件 A,组件 A 又调用组件 B。我不关心组件 B 的执行时间是否为 2 秒,但我关心执行时间是否为 2 秒。例如,组件A的时间低于50ms。 因此,组件 A 向 B 提交消息似乎是最合理的,B 将在所需的时间处理该消息。

我知道不同的 JMS 实现和 Apache ActiveMQ:它们对于这个来说太重量级了。 我搜索了一些轻量级消息传递(具有真正基本的功能,如消息序列化和最简单的路由),但无济于事。

对于这一期,您有什么可以推荐的吗?

I am looking for lightweight messaging framework in Java. My task is to process events in a SEDA’s manner: I know that some stages of the processing could be completed quickly, and others not, and would like to decouple these stages of processing.

Let’s say I have components A and B and processing engine (be this container or whatever else) invokes component A, which in turn invokes component B. I do not care if execution time of component B will be 2s, but I do care if execution time of component A is below 50ms, for example. Therefore, it seems most reasonable for component A to submit a message to B, which B will process at the desired time.

I am aware of different JMS implementations and Apache ActiveMQ: they are too heavyweight for this. I searched for some lightweight messaging (with really basic features like messages serialization and simplest routing) to no avail.

Do you have anything to recommend in this issue?

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

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

发布评论

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

评论(5

绝情姑娘 2024-07-15 00:23:38

您是否需要任何类型的持久性(例如,如果您的 JVM 在处理数千条消息之间死机),并且您是否需要消息遍历到任何其他 JVM?

如果一切都在一个 JVM 中,并且您无需担心 JVM 死机时的事务、恢复或消息丢失 - 那么正如 Chris 上面所说,Executors 就可以了。

ActiveMQ 非常轻量级; 如果您愿意,您可以仅在单个 JVM 中使用它,而无需持久性; 然后,您可以在需要时启用事务/持久性/恢复/远程处理(使用多个 JVM)。 但如果你不需要这些东西那么它就太过分了 - 只需使用 Executors 即可。

顺便说一句,如果您不确定哪些步骤可能需要持久性/可靠性或对多个 JVM 的负载平衡,则另一个选择是 完全隐藏中间件的使用,以便您可以在需要时在带有执行器的内存 SEDA 队列与 JMS/ActiveMQ 之间切换。

例如,某些步骤可能需要可靠且可靠。 可恢复(因此需要某种持久性),而其他时候则不需要。

Do you need any kind of persistence (e.g. if your JVM dies in between processing thousands of messages) and do you need messages to traverse to any other JVMs?

If its all in a single JVM and you don't need to worry about transactions, recovery or message loss if a JVM dies - then as Chris says above, Executors are fine.

ActiveMQ is pretty lightweight; you can use it in a single JVM only with no persistence if you want to; you can then enable transactions / persistence / recovery / remoting (working with multiple JVMs) as and when you need it. But if you need none of these things then its overkill - just use Executors.

Incidentally another option if you are not sure which steps might need persistence/reliability or load balancing to multiple JVMs would be to hide the use of middleware completely so you can switch between in memory SEDA queues with executors to JMS/ActiveMQ as and when you need to.

e.g. it might be that some steps need to be reliable & recoverable (so needing some kind of persistence) and other times you don't.

过去的过去 2024-07-15 00:23:38

真的轻量吗? 执行器。 :-) 因此,您设置了一个执行器(B,在您的描述中),A 只需将任务提交给执行器即可。

Really lightweight? Executors. :-) So you set up an executor (B, in your description), and A simply submits tasks to the executor.

小…楫夜泊 2024-07-15 00:23:38

I think Apache Camel covers all your needs. It's works within the JVM and supports SEDA style (http://camel.apache.org/seda.html) and simpe routing. Can be used on it's own, or with spring, with a JMS provider or other adaptors.

九公里浅绿 2024-07-15 00:23:38

抱歉复活旧线程,但也许它可以帮助其他人阅读它...我认为 FFMQ 是一个轻量级消息传递框架的良好候选者。

更新:但是我不确定它是否支持重新传递延迟(死信队列问题)。 我发现这甚至对于轻量级提供商也有用。 但我想结合 MessageSelector 查询和消息属性是可能的。

Sorry for resurrecting an old thread, but maybe it helps somebody else reading it... I think FFMQ is a good candidate for a lightweight messaging framework.

UPDATE: however I'm not sure if it supports redelivery delays (the dead-letter-queue problem). I would find this usable even for lightweight providers. But I guess it could be possible with a combination of MessageSelector query and message properties.

仅冇旳回忆 2024-07-15 00:23:38

如需帮助其他人,请阅读此主题:
最轻量的消息传递框架之一是 Mbasseder
MBassador 是一个非常轻量级的消息(事件)总线实现,遵循发布订阅模式。 它的设计易于使用,旨在提供丰富的功能和可扩展性,同时保持资源效率和性能。
MBassador 高性能的核心是一种专门的数据结构,它可以最大限度地减少锁争用,从而最大限度地减少并发访问的性能下降。
功能:通过注释进行声明式侦听器定义、同步和/或异步事件传递、弱引用、消息过滤

For help to somebody else read this thread:
One of the lightest messaging framework is Mbasseder.
MBassador is a very light-weight message (event) bus implementation following the publish subscribe pattern. It is designed for ease of use and aims to be feature rich and extensible while preserving resource efficiency and performance.
The core of MBassador's high performance is a specialized data structure that minimizes lock contention such that performance degradation of concurrent access is minimal.
Features: Declarative listener definition via annotations, sync and/or async event delivery, weak-references, message filtering

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