Rest – Observer pattern for rest services with UI client

observer-patternpushrestserver

I am developing restful services using resteasy for an application. This application has UI which will consume these rest services.

Now I am having a case where I have to do a server push to UI(Client).
Across browsing over internet I see Websockets, atmosphere2.0, etc.., however I am wondering how I can capture all the audience using my application to do a server push to the UI.

Also I have to invalidate the connection or time out the user session if there is no activity detected for 30 min.

How can I achieve this?
I have heard of the observer pattern, not sure how it will help in my case.

Best Answer

The old way to do this was to use polling. If you can tolerate some time between the event and the UI seeing it, this might be the easiest way to do it. One thing you could use is a HEAD request on an events resource specific to the client.

If you truly need a push then you probably want to look at something like websockets. I would recommend you limit this to just the event notifications and use standard rest calls to get the data associated with the events.

I took me a little while but I remembered why I have some apprehension about recommending websockets or a similar push approach. The issue I found with websockets was that when everything is connected, it's great but you have to worry about what happens if the connection is dropped. With a polling, if the server is down for a minute or the network hiccups, it will just try again later. It's applicable to this issue for sure but I would make sure you need that level of complexity. I also tried it when it was really new so things could have been done to make it easier.

Related Topic