Search code examples
javaquartz-scheduleratmosphere

Polling an external service with Quartz and sending the results to a client via Atmosphere?


I have a task that I need to do within the next two weeks and I'm currently planning it out. I need to know if this will work how I think it may work.

Here is my current setup.

Server A -- Has a REST interface to communicate with an external service (providing it information on external resources).

Client B -- Will connect to Server A (essentially provides a UI).

Issue: I need to get "active real time updates" from Server A to Client B.

My Solution:

I want to setup Atmosphere on the server and on the client. The client would subscribe to the server and the server will push new information out.

I was thinking of using Quartz to regularly poll the external resource on Server A to allow a constant communication stream to Client B (probably every 10-20 seconds or so).

Does this setup sound feasible? Is there a better way to go about this?


Solution

  • How "real time updates" do you want? If you want updates to happen every 10-20 seconds, then using atmosphere is overkill. Websockets provide realtime updates in a matter of 10-100 miliseconds. To get updates every 10 seconds, you don't need/want continous connection between client and server. It also doesn't make sense to use Quartz for polling server if you are using Atmosphere (push means you DON'T need to poll).

    Use your Server A as http REST endpoint, and use some http client library on Client B like Unirest, and ScheduledExecutorService with scheduleAtFixedRate method to fetch data every 10 seconds.