kdcllc / CometD.NetCore.Salesforce

CometD Salesforce Implementation.
MIT License
45 stars 24 forks source link

Subscribing with the last replay id makes the app receive the older events #36

Open mahesh2080 opened 2 years ago

mahesh2080 commented 2 years ago

The following issue occurs when a session is closed after 3 hours of inactivity. We are subscribing with the last replay id but the app receives older (already received) events.

code in main()

bayeuxClient.AddExtension(new ReplayExtension());
ClientSessionChannelListener clientSessionChannel = new ClientSessionChannelListener();
bayeuxClient.GetChannel(ChannelFields.META_HANDSHAKE).AddListener(clientSessionChannel);

code in ClientSessionChannelListener


public class ClientSessionChannelListener : IMessageListener
{
        public void OnMessage(IClientSessionChannel channel, IMessage message)
        {
            long lastProcessedReplayId = GetLastProcessedReplayId();
            _bayeuxClient.GetChannel('/topic', lastProcessedReplayId).Subscribe(new Listener(_platformEventsMessage, channelInfo));                        
        }
}

If we do not pass the last id, the app does not receive the already processed events (the issue does not occur).

_bayeuxClient.GetChannel('/topic').Subscribe(new Listener(_platformEventsMessage, channelInfo));

alexjoedt commented 1 year ago

Any updates here? I have the same behavior.

EDIT:

This helped: https://github.com/kdcllc/CometD.NetCore.Salesforce/issues/22#issuecomment-894312877

CNBoland commented 8 months ago

IServiceCollection.AddResilientStreamingClient() registers ResilientStreamingClient as a singleton. Something's not being reset that's causing older events to be received. As a workaround, I'm removing the singleton and adding again as scoped.

services.AddResilientStreamingClient();
services.Remove(new ServiceDescriptor(typeof(IStreamingClient), typeof(ResilientStreamingClient), ServiceLifetime.Singleton));
services.AddScoped<IStreamingClient, ResilientStreamingClient>();