Hi Dan, I'm planning on moving into application development with the AMQ AJAX code soon, so this is of interest to me also. There are two types of failure that I can foresee.
One is when the webserver closes the connection due to restart or network problem. In this case, the assumption is that the ActiveMQ server is still running properly and the connection between the browser and the servlet needs to be reestablished. Since the client discovers the disconnect when the XHR throws an exception, the reconnect logic will have to exist in the javascript code. The only appropriate thing I can think of is for the client to immediately attempt to reestablish its polling by invoking sendPoll(). In a production environment, there should be multiple backend servers properly load balanced so this poll request is immediately handled. In a development environment or a less-robust production environment, it will be helpful to have a counter for unsuccessful reconnect attempts and delay (delay*2 ms) between attempts. After a certain number of reconnect attempts, a warning/error to the user can be issued. The second type of failure to handle may be when ActiveMQ crashes. I haven't played around with this scenario, but I believe that a properly clustered group of AMQ servers should automatically handle failover without the web client noticing. This is because the web client only knows about its connection to the AjaxServlet->MessageListenerServlet->MessageServletSupport. I could put the retry logic into the amq.js file, but it sounds like you may have done that already. The only thing I would ask for is some pluggability or config settings around the process. It will vary by type of application and the deployment architecture how these types of failures are handled. Please add any other failure scenarios to this thread. Hopefully we can all contribute some real world robustness to the amq.js file. As it stands in the HEAD, AJAX support is there, but certainly not production worthy. -- jim Dan The Man wrote: > > I am using the AJAX client, and I am curious if there is a way to get > the clients to automatically reconnect? > > My clients work in an environment where the network connections can be > spotty, and I would like them to automatically resume without the user > having to reload the browser. > > Currently what happens is that if the connection drops temporarily > (such as by unplugging the network cable for a minute and then > plugging it back in) the clients just stop receiving messages and > never resume until the browser is reloaded. > > I was able to get a proof-of-concept working using Jim's refactored > javascript from here: > http://tinyurl.com/288qgl > But I am curious if there is a better or more supported way to implement > this? > > Thanks, > > --Dan > > -- View this message in context: http://www.nabble.com/AJAX-Client-Reconnect-tf4608571s2354.html#a13195630 Sent from the ActiveMQ - User mailing list archive at Nabble.com.