java中的轻量级发布/订阅框架

时间:2021-11-21 19:51:35

Is there a good lightweight framework for java that provides the publish/subscribe pattern?

是否有一个很好的轻量级框架为java提供发布/订阅模式?

Some ideal features

一些理想的功能

  • Support for generics
  • 支持泛型
  • Registration of multiple subscribers to a publisher
  • 向发布者注册多个订阅者
  • API primarily interfaces and some useful implementations
  • API主要是接口和一些有用的实现
  • purely in-memory, persistence and transaction guarantees not required.
  • 纯粹的内存,持久性和事务保证不是必需的。

I know about JMS but that is overkill for my need. The publish/subscribed data are the result of scans of a file system, with scan results being fed to another component for processing, which are then processed before being fed to another and so on.

我知道JMS,但这对我的需求来说太过分了。发布/订阅数据是扫描文件系统的结果,扫描结果被送到另一个组件进行处理,然后在被送到另一个组件之前进行处理,依此类推。

EDIT: All within the same process. PropertyChangeListener from beans doesn't quite cut it, since it's reporting changes on properties, rather than publishing specific items. I could shoehorn ProprtyChangeListener to work by having a "last published object" property, and so published objects. PropertyChangeListeners don't support generics, and are entrenched in property change semantics, rather than pure publish/subscribe. The java.util Observer/Observable pattern would be good, but Oberver is a concrete class.

编辑:所有在同一过程中。来自beans的PropertyChangeListener并没有完全削减它,因为它报告了属性的变化,而不是发布特定的项目。我可以通过拥有“最后发布的对象”属性以及已发布的对象来使用工作模式来使用ProprtyChangeListener。 PropertyChangeListeners不支持泛型,并且在属性更改语义中是根深蒂固的,而不是纯粹的发布/订阅。 java.util Observer / Observable模式会很好,但是Oberver是一个具体的类。

6 个解决方案

#1


13  

JMS is as light or heavy as you configure it. We use for example HornetQ in one project with an in memory queue. It is easy to setup, doesn't need any JNDI based configuration and is really easy to use.

JMS与您配置时一样轻或重。我们在一个具有内存队列的项目中使用HornetQ。它易于设置,不需要任何基于JNDI的配置,并且非常易于使用。

I believe that JMS as an API for Message Pub/Sub is as easy as it gets. (And not easier ;)

我相信JMS作为Message Pub / Sub的API非常简单。 (并不容易;)

#2


25  

It seems this fits the requirements:

这似乎符合要求:

EventBus from Google Guava Library - "Publish-subscribe-style communication between components without requiring the components to explicitly register with one another". It can also be an AsyncEventBus that will dispatch events on another thread.

来自Google Guava Library的EventBus - “组件之间的发布 - 订阅式通信,无需组件明确地相互注册”。它也可以是AsyncEventBus,它将在另一个线程上调度事件。

Some extra options to consider:

一些额外的选择:

  1. If it's in same process it's possible the Observer pattern can be used. Subscribers can add listeners and receive event notifications. Observable is already part of the Java API.

    如果它在同一个过程中,则可以使用Observer模式。订阅者可以添加侦听器并接收事件通知。 Observable已经是Java API的一部分。

  2. FFMQ is a full Java, light-weight, Fast JMS 1.1 Queue implementation.

    FFMQ是一个完整的Java,轻量级,快速JMS 1.1队列实现。

#3


6  

Since you're using Spring, I don't know if you're aware that Spring has its own lightweight event framework. It's used primarily within the framework itself, but it's perfectly usable by application code.

既然你正在使用Spring,我不知道你是否意识到Spring有自己的轻量级事件框架。它主要在框架内部使用,但它完全可以被应用程序代码使用。

By default, it's synchronous pub/sub, but you can make it asynchronous using an ApplicationEventMulticaster.

默认情况下,它是同步pub / sub,但您可以使用ApplicationEventMulticaster使其异步。

#4


1  

I think Camel is also a good candidate. Especially with the publish-subscribe pattern

我认为骆驼也是一个很好的候选人。特别是发布 - 订阅模式

Camel can be embedded and is lightweight. It proposes Enterprise Integration Patterns - many useful tools for integration, inside an application or even with other actors (hence 'Integration').

骆驼可以嵌入并且重量轻。它提出了企业集成模式 - 许多有用的集成工具,应用程序内部甚至其他参与者(因此“集成”)。

It compares to Spring Integration but more complete IMO.

它与Spring Integration相比,但更完整的IMO。

#5


0  

If you are crossing process boundaries then some degree of "weight" is going to be incurred. Why do you say that JMS is heavyweight? The API is quite simple? There are supposedly light-weight implementations, for example link text heavier costs such a persistence and transactionality are optional.

如果您正在跨越流程边界,那么将会产生一定程度的“重量”。为什么你说JMS是重量级的? API很简单?据称有轻量级实现,例如链接文本较重的成本,例如持久性和事务性是可选的。

What do you need that is lighter than this?

你需要什么比这更轻?

#6


0  

Bob Lee has a QueueFile class at http://snipt.org/GWm/ that you might find interesting. It's a simple persistent queue and could be used by multiple consumers. It sounds like you don't need persistence, but since the whole thing is so lightweight it could still be useful.

Bob Lee在http://snipt.org/GWm/上有一个QueueFile课程,您可能会感兴趣。它是一个简单的持久队列,可供多个消费者使用。听起来你不需要持久性,但因为整个事情都很轻巧所以它仍然有用。

#1


13  

JMS is as light or heavy as you configure it. We use for example HornetQ in one project with an in memory queue. It is easy to setup, doesn't need any JNDI based configuration and is really easy to use.

JMS与您配置时一样轻或重。我们在一个具有内存队列的项目中使用HornetQ。它易于设置,不需要任何基于JNDI的配置,并且非常易于使用。

I believe that JMS as an API for Message Pub/Sub is as easy as it gets. (And not easier ;)

我相信JMS作为Message Pub / Sub的API非常简单。 (并不容易;)

#2


25  

It seems this fits the requirements:

这似乎符合要求:

EventBus from Google Guava Library - "Publish-subscribe-style communication between components without requiring the components to explicitly register with one another". It can also be an AsyncEventBus that will dispatch events on another thread.

来自Google Guava Library的EventBus - “组件之间的发布 - 订阅式通信,无需组件明确地相互注册”。它也可以是AsyncEventBus,它将在另一个线程上调度事件。

Some extra options to consider:

一些额外的选择:

  1. If it's in same process it's possible the Observer pattern can be used. Subscribers can add listeners and receive event notifications. Observable is already part of the Java API.

    如果它在同一个过程中,则可以使用Observer模式。订阅者可以添加侦听器并接收事件通知。 Observable已经是Java API的一部分。

  2. FFMQ is a full Java, light-weight, Fast JMS 1.1 Queue implementation.

    FFMQ是一个完整的Java,轻量级,快速JMS 1.1队列实现。

#3


6  

Since you're using Spring, I don't know if you're aware that Spring has its own lightweight event framework. It's used primarily within the framework itself, but it's perfectly usable by application code.

既然你正在使用Spring,我不知道你是否意识到Spring有自己的轻量级事件框架。它主要在框架内部使用,但它完全可以被应用程序代码使用。

By default, it's synchronous pub/sub, but you can make it asynchronous using an ApplicationEventMulticaster.

默认情况下,它是同步pub / sub,但您可以使用ApplicationEventMulticaster使其异步。

#4


1  

I think Camel is also a good candidate. Especially with the publish-subscribe pattern

我认为骆驼也是一个很好的候选人。特别是发布 - 订阅模式

Camel can be embedded and is lightweight. It proposes Enterprise Integration Patterns - many useful tools for integration, inside an application or even with other actors (hence 'Integration').

骆驼可以嵌入并且重量轻。它提出了企业集成模式 - 许多有用的集成工具,应用程序内部甚至其他参与者(因此“集成”)。

It compares to Spring Integration but more complete IMO.

它与Spring Integration相比,但更完整的IMO。

#5


0  

If you are crossing process boundaries then some degree of "weight" is going to be incurred. Why do you say that JMS is heavyweight? The API is quite simple? There are supposedly light-weight implementations, for example link text heavier costs such a persistence and transactionality are optional.

如果您正在跨越流程边界,那么将会产生一定程度的“重量”。为什么你说JMS是重量级的? API很简单?据称有轻量级实现,例如链接文本较重的成本,例如持久性和事务性是可选的。

What do you need that is lighter than this?

你需要什么比这更轻?

#6


0  

Bob Lee has a QueueFile class at http://snipt.org/GWm/ that you might find interesting. It's a simple persistent queue and could be used by multiple consumers. It sounds like you don't need persistence, but since the whole thing is so lightweight it could still be useful.

Bob Lee在http://snipt.org/GWm/上有一个QueueFile课程,您可能会感兴趣。它是一个简单的持久队列,可供多个消费者使用。听起来你不需要持久性,但因为整个事情都很轻巧所以它仍然有用。