Jalal
Jalal

Reputation: 1246

Pushing near real time data in a Java WebApp

There is this java web application with a lot of users. These users place some orders according to the data shown in their panels. The data is being updated second by second by calling an outsider service (via a webservice or so). The moment we get this data, users' panels must be updated immediately to make sure that users are placing valid orders.

So we need to push data to the client WebApp. Performance and reliability are of great concern. What approach or technology do you suggest here? Should I use somthing like Comets? Or is using primitive WebSockets suitable?

Upvotes: 0

Views: 560

Answers (2)

Nasir
Nasir

Reputation: 2984

There are a bunch of things to consider.

There are various technologies. You've mentioned Comet. There is also Web Sockets. Without support at the protocol level, you are stuck with pretty much polling for data. This is the approach Comet takes.

Web Sockets is specifically designed for this. It has far less overhead than a TCP or UDP based message stream.

Are you targeting modern browsers or also need to support older browsers?

There is varied support for protocols, across versions, implementations may have some caveats and so on.

Or is using primitive WebSockets suitable?

It is perfectly acceptable. Though you have to deal with variances with browser differences, or you may find porting your web sockets across web servers may require some work.

For instance, if you are deploying on Jetty (and using its API natively), you need to implement WebSocketCreator. If you are using Grizzly natively, you need to implement WebSocketListener and so on.

Atmosphere tries to fix this by providing a uniform interface which works across various servers. Again, once you pick such a library, you will need to make changes if you want a different library in the future.

Or you could do use a service like Pusher or any of its competitors.

If you Google around, you should be able to find plenty of examples.

Hopefully it helps.

Upvotes: 1

vbezhenar
vbezhenar

Reputation: 12336

Websocket is the fastest transport but it's not supported well (by old versions of Internet Explorer).

AJAX requests are not that fast (because browser potentially will establish new HTTP connection and HTTP headers introduce overhead too) but much better supported. And with correct keep-alive settings HTTP connection should be reused.

You can use some generic implementation like sock.js (well supported by Spring framework). It'll choose the best available transport automatically. But it introduces an additional layer of complexity.

Upvotes: 1

Related Questions