使用 JMS 发布订阅的 Java EE 替代方案

发布于 2024-12-09 00:22:05 字数 316 浏览 0 评论 0原文

我是 Java EE 的新手,一直在寻找一种无需使用 JMS 即可实现发布/订阅类型模型的通用方法。我有兴趣创建一个简单的应用程序,当字符串从服务器推送到客户端时显示字符串。我想调查的是在不进行轮询的情况下执行此操作以减少不必要的请求。事件会有很大变化,因此我认为在设定的时间内进行轮询并不是最好的解决方案,但客户端应该立即显示事件。

我读过在 Java EE 之外执行此操作的不同方法,例如带有套接字 api 的 HtML5。但我想知道如何在 Java EE 中做到这一点,我假设有一些非常常见的东西可以做到这一点,但我还没有遇到过。实际上,我只是在寻找技术名称,以便我可以对其实现进行进一步的研究。

I'm new to Java EE and have been looking for a common way to implement a publish/subscribe type model without having to use JMS. I'm interested in creating a simple app that displays strings as they are push from the server to the client. I want to investigate was of doing this without polling to reduce unnecessary requests. The events would be varied quite a bit so I don't think polling over a set amount of time would be the best solution but the client should display the event immediately.

I've read about different ways of doing this outside of Java EE such as HtML5 with sockets api. But I want to know how to do this in Java EE, I'm assuming there is something very common that does this but I have not come across it yet. Really I'm just looking for the technology name so that I can do further research on its implementation.

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

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

发布评论

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

评论(4

心病无药医 2024-12-16 00:22:05

也许 Hazelcast 值得您看看。它为发布/订阅消息传递提供了易于使用的分布式主题功能。

文档中的一个简单示例:

import com.hazelcast.core.Topic;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

public class Sample implements MessageListener {

    public static void main(String[] args) { 
        Sample sample = new Sample();
        Topic topic = Hazelcast.getTopic ("default");  
        topic.addMessageListener(sample);
        topic.publish ("my-message-object");
    }  

    public void onMessage(Object msg) {
        System.out.println("Message received = " + msg);
    } 
}

Maybe Hazelcast is worth for you to have a look at. It offers an easy to use Distributed Topic feature for publish/subscribe messaging.

A simple example from the docs:

import com.hazelcast.core.Topic;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

public class Sample implements MessageListener {

    public static void main(String[] args) { 
        Sample sample = new Sample();
        Topic topic = Hazelcast.getTopic ("default");  
        topic.addMessageListener(sample);
        topic.publish ("my-message-object");
    }  

    public void onMessage(Object msg) {
        System.out.println("Message received = " + msg);
    } 
}
只是我以为 2024-12-16 00:22:05

我只会回答Java EE部分,因为我不熟悉你引用的Apple技术。

在我看来,企业 Java 不适合这种任务。 Java EE 应用程序的主要用例是:“许多用户在集中式应用程序上执行大量小型且大部分独立的任务”。 Java EE 为中央应用程序提供了扩展到任意数量用户的方法。发起和引导对话的主要是用户

但是,您的用例要求服务器成为活动部分。当然,您可以在 Java EE 应用程序服务器上运行几乎任何类型的逻辑,也可以运行异步任务,但这并不意味着您应该这样做。

I'll answer only the Java EE part, as I'm not familiar with the Apple technology you quoted.

It seems to me enterprise Java is not appropriate for this kind of task. The main use case for a Java EE application is: "lots of users do lots of small, mostly independent tasks on a centralized application". Java EE provides means for the central application to scale to any number of users. And it's mostly users who initiate and steer the dialogue.

Your use case, however, requires the server to be the active part. You can, of course, run almost any kind of logic on a Java EE application server, asynchronous tasks, too, but it doesn't mean you should.

绮筵 2024-12-16 00:22:05

我不是这个主题的专家,但由于没有人回答,我将尝试解释我所知道的。

首先,J2EE 使用 JMS 规范作为其基本的发布/订阅机制。有各种 JMS 代理。这里重要的一点是,其中一些代理没有专门绑定到任何 J2EE 应用程序服务器,并且可以独立工作。查看 Apache 的 ActiveMQ,它作为独立的 JMS 代理运行良好。它与许多语言都有很好的绑定。因此您可以使用 JMS 代理自由地构建非 J2EE 架构。

其次,还有其他符合其他标准的消息队列代理,这些标准也可以在 J2EE 体系结构中使用。 DDS(数据分发服务)就是一个例子。它是一个 OMG 标准,具有 Java 绑定,如果需要,可以在 J2EE 架构中使用。

第三,Web 服务标准定义了 WS-Notification Broker 标准。据我所知,这并不是 J2EE 的一部分,但许多 SOA 提供商都支持。

因此,您有许多可以在 J2EE 架构中自由混合的替代方案。

我希望这有帮助。

I am not an expert on this topic but since no one has answered I will try to explain what I know.

First of all J2EE uses JMS spec as its fundamental publish/subcribe mechanism. There are various JMS brokers out there. The important point here is that some of these brokers are not specifically tied to any J2EE application server and can work stand alone. Check out Apache's ActiveMQ and it works well as a standalone JMS broker. It has bindings to many languages a well. So you can freely compose a non J2EE architecture using a JMS broker.

Second, there are other message queue brokers that comply to other standards that can be used within a J2EE architecture as well. DDS (Data Distribution Service) is an example. It is an OMG standard and has bindings for Java and can be used in a J2EE architecture if desired.

Third, Web Services standards define a WS-Notification Broker standard. Again this is not part of J2EE as far as I know but is supported by many SOA providers.

So you have many alternatives that can be freely mixed in J2EE architecture.

I hope this helps.

动听の歌 2024-12-16 00:22:05

Redis 有一个可能令人感兴趣的发布/订阅机制:http://redis.io/topics/pubsub

Redis has a Publish/Subscribe mechanism that may be of interest: http://redis.io/topics/pubsub

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