We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
看看 eventbus。
(链接已修复;感谢 jldupont 指出这一点)。
Have a look at eventbus.
(Link fixed; thanks to jldupont to point that out).
我知道这是一个老问题,但我认为更现代的解决方案是使用 Guava 的事件总线(当然,我不确定它是否适用于 GWT,但您的标题和标签都没有说 GWT)。
我实际上有一个自定义 RabbitMQ 简单消息容器 它将自动创建队列绑定和收到的消息将分派到 Guava EventBus。其优雅程度令人难以置信,而且规模极佳。
您可以轻松地使用 DI 框架来注册订阅者。对于 Spring,我创建了 BeanPostProcessor,它将自动使用
@Subscribe
注册 bean。下面是 Spring BeanPostProcessor:
我确信在 Guice 中做类似的事情是微不足道的。
I know this is an old question but I think a more modern solution is to use Guava's Event Bus (granted I'm not sure if it will work for GWT but both your title and tags don't say GWT).
I actually have a custom RabbitMQ simple message container that will automatically create queue bindings and on messages received will then dispatch to Guava EventBus. Its incredible elegant, and scales superbly.
You can easily use your DI framework to register the Subscribers. For Spring I create BeanPostProcessor that will automatically registers beans with
@Subscribe
.Below is the Spring BeanPostProcessor:
I'm sure is trivial to do something similar in Guice.
如果您碰巧已经在使用 Spring,那么 Spring 的一个方便的隐藏功能就是 ApplicationEventMulticaster 接口,这是一个非常简单的 API,用于发布和订阅应用程序生成的事件。这些实现使用
TaskExecutor
框架,这意味着它们可以根据需要同步或异步。此外,每个ApplicationContext
都有一个publishEvent
方法,因此为 Spring 管理的类设置它非常容易。所以,是的,如果您已经使用 Spring,则无需使用其他实用程序来执行此操作,它已经内置了。
If you happen to be using Spring already, then a handy sort-of-hidden feature of Spring is the ApplicationEventMulticaster interface, which is a very simple API for publishing and subscribing to application-generated events. The implementations use the
TaskExecutor
framework, which means they can be sync or async as desired. Furthermore, everyApplicationContext
has apublishEvent
method, so it's comically easy to set it up for Spring-managed classes.So yes, if you already use Spring, there's no need to for another utility to do this, it's built in already.
不确定它是否真的很轻。但它确实符合您的描述的其余部分: ActiveMQ
Not sure if it is really lightweight. But it does fit the rest of your description: ActiveMQ
也许您可以尝试一些基于 jabber (XMPP) 的解决方案。开火呢?
Maybe you could try some jabber (XMPP) based solution. What about openfire?