My Java application needs to fetch data from server (running CakePHP on nginx). Is there an alternative way to fetch data without polling server? Currently I am making use of persistent HTTP connection and polling server every X seconds to see if any data is available.
Had it been a web browser, I could have used web sockets. What options do we have in Java?
If you can implement some kind of Java Messaging System (JMS) like ActiveMQ, RabbitMQ, WebsphereMQ, etc then you can listen for messages posted to your client. Of course your Java application still effectively polls for messages, but the performance would be much better than HTTP requests.
The Spring framework offers some excellent abstractions over a JMS implementation so you don’t have to worry about the plumbing. You can either go with a simple JmsTemplate or use Spring Integration as two options