Reputation: 1360
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.
Upvotes: 4
Views: 1960
Reputation: 10762
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.
Upvotes: 1
Reputation: 35048
Redis has a Publish/Subscribe mechanism that may be of interest: http://redis.io/topics/pubsub
Upvotes: 0
Reputation: 10750
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);
}
}
Upvotes: 3
Reputation: 6829
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.
Upvotes: 1