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

Resubscribing after advice:"reconnect:handshake" #38

Open
Wangofandango opened this issue Oct 25, 2023 · 0 comments
Open

Resubscribing after advice:"reconnect:handshake" #38

Wangofandango opened this issue Oct 25, 2023 · 0 comments

Comments

@Wangofandango
Copy link

Hey! I have a problem in a specific situation where i the server i am connecting to (that i dont have control over) sometimes shut off (or just restart). When we lose the connection, we get this error on the longpolling:

{"id":"13641","channel":"/meta/connect","successful":false,"error":"401:lfzlt13a0h2j53oqb9b5mpwhxnn0nov:Unknown client","advice":{"reconnect":"handshake"}}"

And as i see it currently, the handshake is successfully done. But since we are not also "re-" subscribing, then we dont any longer get any messages.

So if someone could please help me get an overview of how i can setup an automatic "Re-Subscribe" feature for when this happens 😓 I have sat with this problem for a very long time now

If it is any help, this is the code i am using when starting my client:

` public RelatelHostedService(IMessageListener messageListener, ILoggerService loggerService)
{
_messageListener = messageListener;
_loggerService = loggerService;

}

public Task StartAsync(CancellationToken cancellationToken)
{
    StartRelatelConnection();
    return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
    RelatelChannel.Unsubscribe();
    RelatelBayeuxClient.Disconnect();
    
    return Task.CompletedTask;
}

private void StartRelatelConnection()
    {
        string relatelServer = Config.RelatelServerEndpoint;
        string companyId = Config.KeyholesCompanyIdAtRelatel;
        string accessToken = Config.RelatelAccessToken;
        
        
        //"Options" for the longpolling transport (such as timout, interval, etc)
        Dictionary<string, object> options = new Dictionary<string, object>();
        
        
        //Optional HTTP headers to be sent with the longpollingtransport
        NameValueCollection httpHeaders = new NameValueCollection();
        
        LongPollingTransport clientTransport = new LongPollingTransport(options, httpHeaders);
        RelatelBayeuxClient = new BayeuxClient(relatelServer, clientTransport);
       
        //Adds access_token to outgoing meta messages, (so far only used on Subscribing)
        RelatelBayeuxClient.AddExtension(new AuthTokenExtension(accessToken, _loggerService));
        
        RelatelBayeuxClient.Handshake();
        RelatelBayeuxClient.WaitFor(10000, new List<BayeuxClient.State> { BayeuxClient.State.CONNECTED });
    }

}`

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

1 participant