You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Dan Schooler <da...@gmail.com> on 2007/10/11 18:41:17 UTC

AJAX Client Reconnect

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

Re: AJAX Client Reconnect

Posted by Gul <sg...@i2cinc.com>.
hi Dan!!

i am using your latest updated amq.js file with cook's prototype file and
eliminate the amq_prototype_adapter.js.. the problem is that when i want to
call AjaxServlet with the following code 

Ajax.Request(uri, { method: 'post', postBody: body, onSuccess:
org.activemq.Amq.endBatch});

then the AjaxServlet does not get called? Could u plz tell me any solution?

Thanks



Dan The Man wrote:
> 
> Hi Jim,
> 
> I am most concerned with the first type of failure, where the client
> has a problem with the network connection, but the server is still
> running properly. What I did was take your modified amq.js (from link
> in my previous message) and then added the following to line 111 in
> pollErrorHandler() :
> 
> setTimeout(function() { sendPoll(); }, pollErrorDelay);
> 
> That seems to work well enough, but then I am very new to the whole
> AJAX thing, and there is probably a better way. I was hoping that some
> sort of retry logic would make it into the head so that I can use the
> standard javascript files (makes maintenance a lot easier).
> 
>    --Dan
> 
> On 10/13/07, chago <na...@visualxs.com> wrote:
>> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/AJAX-Client-Reconnect-tp13159885p17815678.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: AJAX Client Reconnect

Posted by chago <na...@visualxs.com>.
As you know, none of the javascript rewrite has made it into HEAD. Perhaps
James or a committer on the project can weigh in on the patch I submitted.
If it is in HEAD then it can be improved upon and have these new features
added. Not to say, we can't evolve the code outside of that process, but
then we end of with source control and versioning problems.

-- jim


Dan The Man wrote:
> 
> Hi Jim,
> 
> I am most concerned with the first type of failure, where the client
> has a problem with the network connection, but the server is still
> running properly. What I did was take your modified amq.js (from link
> in my previous message) and then added the following to line 111 in
> pollErrorHandler() :
> 
> setTimeout(function() { sendPoll(); }, pollErrorDelay);
> 
> That seems to work well enough, but then I am very new to the whole
> AJAX thing, and there is probably a better way. I was hoping that some
> sort of retry logic would make it into the head so that I can use the
> standard javascript files (makes maintenance a lot easier).
> 
>    --Dan
> 
> On 10/13/07, chago <na...@visualxs.com> wrote:
>> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/AJAX-Client-Reconnect-tf4608571s2354.html#a13217585
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: AJAX Client Reconnect

Posted by Dan Schooler <da...@gmail.com>.
Hi Jim,

I am most concerned with the first type of failure, where the client
has a problem with the network connection, but the server is still
running properly. What I did was take your modified amq.js (from link
in my previous message) and then added the following to line 111 in
pollErrorHandler() :

setTimeout(function() { sendPoll(); }, pollErrorDelay);

That seems to work well enough, but then I am very new to the whole
AJAX thing, and there is probably a better way. I was hoping that some
sort of retry logic would make it into the head so that I can use the
standard javascript files (makes maintenance a lot easier).

   --Dan

On 10/13/07, chago <na...@visualxs.com> wrote:
> 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

Re: AJAX Client Reconnect

Posted by chago <na...@visualxs.com>.
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.