Oyatel / CometD.NET

CometD.NET is a C# client library for the Bayeux protocol
43 stars 34 forks source link

Cometd/bayeux client Issue - Implementation of "meta/handshake" call back #26

Open swagathchandra opened 3 years ago

swagathchandra commented 3 years ago

I have my .NET client (windows service) which subscribes to Salesforce streaming API CDC.

I am able to connect to Salesforce and can get the notifications to my client. Everything is working fine, but When there is no activity on the channel (no changes for Salesforce object) after some time (maybe 2 hours) if I update the object, I am not receiving any notification from Salesforce. Can anyone please help me, I read in some of previous posts about implementing "meta/callback" but not able to figure out the implementation, below is the code. I will appreciate if anyone can provide me example for implementation of "meta/handshake" to resubscribe the channels

public async Task StartAsync(CancellationToken cancellationToken) { appLifetime.ApplicationStarted.Register(OnStarted); appLifetime.ApplicationStopping.Register(OnStopping); appLifetime.ApplicationStopped.Register(OnStopped);

        logger.LogInformation("StreamingService.StartAsync has been called.");

        logger.LogInformation("Authenticating with Salesforce...");
        var authToken = await salesforceClient.GetToken();

        logger.LogInformation("Enabling Bayeux protocol...");
        var options = new Dictionary<String, Object>
        {
           { ClientTransport.TIMEOUT_OPTION, readTimeOut }
        };

        var headers = new NameValueCollection { { "Authorization", "OAuth " + authToken.AccessToken } };
        var transport = new LongPollingTransport(options, headers);
        var serverUri = new Uri(authToken.InstanceUrl);
        var endpoint = $"{serverUri.Scheme}://{serverUri.Host}{sfOptions.StreamEndpoint}";

        bayeuxClient = new BayeuxClient(endpoint, new[] { transport });
        logger.LogInformation("Handshaking with Salesforce stream...");
        bayeuxClient.Handshake();
        bayeuxClient.WaitFor(1000, new[] { BayeuxClient.State.CONNECTED });
        logger.LogInformation("Connected to Salesforce stream...");
        bayeuxClient.GetChannel(sfOptions.Channel).Subscribe(new Listener(logger));
        logger.LogInformation("Waiting for data from server...");
    }
PierreC82 commented 1 year ago

Did you solve the problem? I have exactly the same problem.