0

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 ??

Dipankar Dey
  • 105
  • 1
  • 8

1 Answers1

0

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.

sbordet
  • 16,856
  • 1
  • 50
  • 45
  • Thanks for your response. I have added my implementation details in the question can you please have a look ? – Dipankar Dey Feb 22 '18 at 02:45
  • Well that is a different question altogether :) If the new token is already valid at minute 29 (and therefore both the old and the new token are valid), then you only need to change the `accessToken` value at minute 29 in `customize(Request request)` and you will be good. You don't need to do anything at the CometD level since this is only at the transport (HTTP) level. – sbordet Feb 22 '18 at 08:46
  • Hi Simone, At first place I did it like the way you mentioned in the comment ,but after a while (like after 7-8 hours) it stopped receiving the messages from broadcast channel . An then when it tried to re handshake again just by calling hanshake() again it got exception as illegalstate. Please tell me which step I'm missing here or how to recover listener while failure happens? Do I need to restart the bayeux client in this case ?? – Dipankar Dey Feb 22 '18 at 10:25
  • So why did it stop after 7-8 hrs that was working fine ? – sbordet Feb 22 '18 at 14:12
  • 1
    Actually I'm connecting to salesforce bayeux server. May be they are making it required to handshake after a certain period of time not sure though. when it disconnected it got the following messages via 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} – Dipankar Dey Feb 22 '18 at 14:28
  • Hmm seems like I got what you are trying to say here. If I'm not wrong according to you the advice message is being taken care by cometd itself which is supposed to handshake in case of any re handshake required. Actually I started the client at night and it was still working on the morning but when I trigger or update something in salesforce back end it did not gave me any broadcast channel message. This is the actuall problem here. – Dipankar Dey Feb 22 '18 at 14:40
  • I think i need to raise support ticket in salesforce as well since as per you my implementation is correct and my application should not do any explicit re hanshake upon any failure. – Dipankar Dey Feb 22 '18 at 14:43