Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection issue #3

Closed
srkamineni opened this issue Mar 12, 2011 · 8 comments
Closed

Reconnection issue #3

srkamineni opened this issue Mar 12, 2011 · 8 comments

Comments

@srkamineni
Copy link

After the server goes down, the .net client is not reconnecting at all. My understanding was that it clients will try to reconnect after the server goes down.

Or is there any thing that we can do to reconnect.

Thanks
Raj

@grEvenX
Copy link

grEvenX commented Mar 23, 2011

Thanks for the observation Raj. This is the responsibility of the library for sure, and I'm pretty sure we tested this well on our end.
How are you able to confirm that it does not "reconnect" ?
It should reconnect to the server, but the question might be what is happending for subscribtions etc.

@srkamineni
Copy link
Author

Well, after the server went down and came back up, the client never received any messages from the server. I had to restart my .net client to connect back again and start getting the messages.

I am wondering if I am missing some addition of a listener - like disconnect and then connect again. What do you suggest.

Raj

@guruprasad83
Copy link

@srkamineni - Even am facing the same issue - Well, after the server went down and came back up, the client never received any messages from the server. I had to restart my .net client to connect back again and start getting the messages.
Did you get any solution for this? Am also using .net client

@ohaucke
Copy link

ohaucke commented May 15, 2018

@guruprasad83
I've implemented an extension which raises an event if the connection got closed by the server.
You could check the message in rcvMeta and modify the code to match your response and raise the event.

using Cometd.Bayeux;
using Cometd.Bayeux.Client;
using System;

namespace Foobar.Utilities
{
    public class LoggingExtension : IExtension
    {
        private static NLog.Logger logger = NLog.LogManager.GetLogger("Foobar");

        public event EventHandler ConnectionError;

        public bool rcv(IClientSession session, IMutableMessage message)
        {
            return true;
        }

        public bool rcvMeta(IClientSession session, IMutableMessage message)
        {
            if (message.Successful)
            {
                logger.Debug(message.JSON);
            }

            if (message.ContainsKey("exception"))
            {
                logger.Fatal(message["exception"]);
            }

            if (message.ContainsKey("error"))
            {
                logger.Error(message["error"]);
                if (message["error"].ToString().ToLower() == "403::unknown client")
                {
                    this.OnConnectionError();
                }
            }

            return true;
        }

        public bool send(IClientSession session, IMutableMessage message)
        {
            return true;
        }

        public bool sendMeta(IClientSession session, IMutableMessage message)
        {
            return true;
        }

        private void OnConnectionError()
        {
            this.ConnectionError?.Invoke(this, new EventArgs());
        }
    }
}

Afterwards you need to add the extension to your bayeuxClient and subscribe to the event where you can re-establish the connection

LoggingExtension loggingExtension = new LoggingExtension();
loggingExtension.ConnectionError += loggingExtension_ConnectionError;
bayeuxClient.addExtension(loggingExtension);

@swagathchandra
Copy link

@ohaucke - Can you please share code for extension. I am facing the same issue

@ohaucke
Copy link

ohaucke commented Dec 3, 2020

@swagathchandra I already posted it (LoggingExtension)

@nahoj28
Copy link

nahoj28 commented Jul 16, 2021

Hi @ohaucke , Thanks for the information. It is very helpfull for me, however I'm not sure of understand what is the steps to add into the EventHanlder (loggingExtension_ConnectionError). Should I connect to the instance again into the handler? or into the hanlder only is needed subscribe to the channels again?

@ohaucke
Copy link

ohaucke commented Jul 17, 2021

Hi @nahoj28, sorry that is way in the past, so i don't remember it but from the code, i would say you need to completely reconnect because the accesstoken isn't valid anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants