Pushing messages to connected clients has always been a need on the web, growing with the apparition of new Rich Internet Applications, like realtime feeds (Gmail, news, market quotes), social feeds (The Twitter, Facebook and consort) and many other providing realtime collaboration, monitoring and control like new Internet of Things applications (FlightRadar24, Arduino #1, #2).
Today, when you want to enable realtime push on your own Java-based webapp, you have several solutions:
- Use an externalized system that will handle that for you (like Pusher), avoiding you the providing of any additional server
- Use a commercial solution (like Kaazing or Diffusion), generally implementing a Message Broker underneath, with both embedded and standalone server
- Use a container-specific api (like Jetty Continuation, Tomcat’s CometProcessor, Grizzly CometHandler or Netty WebSocket), but your application will be strongly coupled with it
- Or use one of the few Open Source frameworks available (like Atmosphere, cometD or JWebSocket)
In this article, I will focus on Atmosphere. After a brief presentation of the framework, I will demonstrate how easy it is to make push-capable applications, whatever the container you use and the nature of your clients.
Before we start, you can take a look at the following video, that demonstrates what I achieved thanks to the Atmosphere framework (more details below, of course):