My application is subscribed to some Broadcast Bayeux channel. It also listen's to meta channels to receive any advice in case of any connection failure via /meta/connect. Now my question is do I need to restart my Bayeux client i.e first disconnect() and try handshake() again Or only handshake() call is enough to get the connection back when I get reconnect=handshake as advice ??
Please comment for any further info on this.
This is how I set up the longpolling connection for bayeux client
LongPollingTransport transport = new LongPollingTransport(options,
httpClient) {
@Override
protected void customize(Request request) {
request.header("Authorization", "OAuth " + accessToken);
}
};
Now this access token which I'm passing through request header has some refresh time value. Lets say it is 30 mins. These are implementation which I did
Fisrt Implementation:
In every 120 mins I used client.unsubsrcibe and client re handshake() but got illegalstate exception. Seemed like disconnect is required to re handshake not sure though. So used restart the client on every 120 min . But this way listeners were dropped may be due to invalid accessToken as I'm not updating it on every 29 mins.
Second Implementation :
In every 29 mins I used re login get new connection accessToken so that on every callback to this customize method will have valid token .
Above mechanism failed after sometime and listeners were dropped. And got the following from meta/connect
{"clientId":"4hi1pg62ce7bri39fnv3apg4j5ch","advice":{"reconnect":"handshake","interval":500},"channel":"/meta/connect","id":"103","error":"403::Unknown client","successful":false}
{"clientId":"5atyxwdtyoggv4s1v3ce4dobm9u9","advice":{"reconnect":"handshake","interval":500},"channel":"/meta/connect","id":"2203","error":"403::Unknown client","successful":false}
Third Implementation :
In my second implementation I triggered client.disconnect() and client.hanshake() depending on the meta/connect message i.e whenever i get reconnect = handshake i do disconnect and handshake and it is still working properly without any error.
Can you tell what am I missing and what should be the correct way to implement these scenario ??
You don't need to do anything.
The information carried by the advice
field is handled by the implementation, so your application (or any application) should not perform any action based on the information of the advice
field.
For applications, the advice
field is just informative.