BayeuxServer shutdown - reconnect BayeuxClients?

274 views
Skip to first unread message

Henjo van Rees

unread,
May 14, 2012, 4:15:32 AM5/14/12
to cometd...@googlegroups.com
I'm using BayeuxServer + multiple BayeuxClients to communicate (no JS involved).
Everything is working fine, all clients can send and receive messages alright.

However, when I shutdown the server the clients are not reconnected.

Is this something I have to take care of myself? Or can i tell BayeuxClients to detect broken connections are restart the handshake + subscription?

Simone Bordet

unread,
May 14, 2012, 4:56:14 AM5/14/12
to cometd...@googlegroups.com
Hi,
BayeuxClient attempts to reconnect automatically, by default, using a
backoff algorithm.

What CometD version are you using ?

Enable debug logging on the client that's not reconnecting, and see
what it says about.

There is a test that shows BayeuxClient is reconnecting automatically:
https://github.com/cometd/cometd/blob/master/cometd-java/cometd-java-client/src/test/java/org/cometd/client/ServerRestartTest.java

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

Henjo van Rees

unread,
May 14, 2012, 5:12:32 AM5/14/12
to cometd...@googlegroups.com
 I am using Cometd 2.4.1.
I just checked, the client is not reconnected after I restart my webserver running Cometd (Jetty).

Client creation code:
    final String CHANNEL = "/events";

    client = new BayeuxClient(URL, LongPollingTransport.create(null));
    client.handshake();
    client.waitFor(1000, BayeuxClient.State.CONNECTED);

    ClientSessionChannel channel = client.getChannel(CHANNEL);
    channel.subscribe(new ClientSessionChannel.MessageListener() {
      public void onMessage(ClientSessionChannel channel, Message message) {
        logger.debug("Received message: " + message);
      }
    });

Simone Bordet

unread,
May 14, 2012, 5:15:23 AM5/14/12
to cometd...@googlegroups.com
Hi,
This code does not check for reconnections.

Perhaps you should explain better what you expect.

Note that if you shutdown the server, all information about the client
is lost, included subscriptions, so you can't expect to receive
messages on channels you subscribed *before* shutting down the server.

Henjo van Rees

unread,
May 14, 2012, 5:22:52 AM5/14/12
to cometd...@googlegroups.com
If I restart the BayeuxServer, the clients do not know that the channel they were listening on is "gone".
After the server is restarted and new messages are sent on the channel, the clients do not receive these messages.

You say that BayeuxClients automatically reconnect, but I'm not seeing that behaviour.

What I expect (or would like to achieve) is that BayeuxClients reconnect + resubscribe after a server restart.
Must I add code in the client that checks if it's still connected and subscribed to a channel?




Op maandag 14 mei 2012 10:15:32 UTC+2 schreef Henjo van Rees het volgende:

Simone Bordet

unread,
May 14, 2012, 5:39:47 AM5/14/12
to cometd...@googlegroups.com
Hi,

On Mon, May 14, 2012 at 11:22 AM, Henjo van Rees <hen...@gmail.com> wrote:
> If I restart the BayeuxServer, the clients do not know that the channel they
> were listening on is "gone".
> After the server is restarted and new messages are sent on the channel, the
> clients do not receive these messages.
>
> You say that BayeuxClients automatically reconnect, but I'm not seeing that
> behaviour.
>
> What I expect (or would like to achieve) is that BayeuxClients reconnect +
> resubscribe after a server restart.
> Must I add code in the client that checks if it's still connected and
> subscribed to a channel?

Your subscriptions should be done from a successful /meta/handshake
handler, on the client, see
http://docs.cometd.org/reference/#java_client_subscribe.

Let us know if it worked.

Henjo van Rees

unread,
May 14, 2012, 6:00:02 AM5/14/12
to cometd...@googlegroups.com
Yes, subscribing to the /meta/handshake channel was exactly what I needed in the clients.
Thanks!
Reply all
Reply to author
Forward
0 new messages