Oyatel / CometD.NET

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

Cometd/bayeux client + salesforce streaming API issue #23

Closed guruprasad83 closed 6 years ago

guruprasad83 commented 6 years ago

I have my .net client (windows service) which subscribe for Salesforce streaming API push topics using this cometd.net.

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 am not receiving any notification from salesforce. I had tried putting listeners to log and in the logs it says below

> {"clientId":"f6xo67iet55w5j7ek6ldw72nfc6","channel":"/meta/connect","id":"82","successful":true} 5/15/2018 8:12:28 PM
> 
> {"advice":{"interval":0,"reconnect":"handshake"},"channel":"/meta/connect","id":"83","error":"403::Unknown client","successful":false} 5/15/2018 8:12:28 PM
> 
> {"clientId":"hbx1v2cxebbeder11s99dqkxmasre","advice":{"interval":0,"timeout":110000,"reconnect":"retry"},"channel":"/meta/connect","id":"85","successful":true} 5/15/2018 8:12:29 PM
> 
> {"clientId":"hbx1v2cxebbeder11s99dqkxmasre","channel":"/meta/connect","id":"86","successful":true} 5/15/2018 8:14:20 PM
>
> {"clientId":"hbx1v2cxebbeder11s99dqkxmasre","channel":"/meta/connect","id":"87","successful":true} 5/15/2018 8:16:10 PM

so as per the log, sometimes I get "403::Unknown client" but immediately after that it says again channel successful. But as I said when I try updating salesforce object after 2 hours (as per log, it is in connection successful) I am not receiving any notification.

If I restart my windows service and gets the notification again.

Any help would be greatly appreciated Sorry if I post it here as i did not get any solution so.

ohaucke commented 6 years ago

I had the same issue and implemented/added an extension, that raises an event in which i than restart the connection (auth + subscription)

https://github.com/Oyatel/CometD.NET/issues/3#issuecomment-389085182

guruprasad83 commented 6 years ago

@ohaucke - Thanks for your comment. Actually after some more research it's working now for me. Here are the changes to be done (in case if anyone wants)

  1. Whenever there is a "403::Unknown client", CometD tries to reconnect (default behavior of cometd)
  2. Once it reconnects, all the channel subscriptions will be removed (which was happening in my case)
  3. So, the solution is, we always need to do channel subscription on "meta/Handshake" callback. This is what even cometd.org also recommends to do.
  4. This will ensure that on every handshake channels will be in sync
  5. After doing this my salesforce sync was working fine even if we don't update any object from salesforce and then try after 2 days it still works.
Rajat-Jindal commented 6 years ago

@guruprasad83 / @ohaucke : I am also getting the same issue.

I have added the code in the event handler to handshake and subscribe channel (pushTopicConnection.Connect method) in the raised event as you mentioned above but still, it's not working. Is there anything else I need to do or i am missing something?

Thanks In Advance

guruprasad83 commented 6 years ago

@Rajat-Jindal - see the steps below

  1. Create a bayeuxclient by passing salesforce accesstoken and url
  2. once bayeuxclient created, add an event listener for handshake channel like below bayeuxClient.getChannel("/meta/handshake").addListener(handshakeListener); where handshakeListener is an event listener (HandShakeChannelListener)
  3. on success event of handshakeListener, you subscribe to pushtopics
xs2bharat commented 4 years ago

@guruprasad83 I am trying to add handshakelistener as per your above comments but not sure if i am missing something. I am also using .net library you mentioned.

My code is - this.bayeuxClient.GetChannel("/meta/connect").AddListener(new Listener()); this.bayeuxClient.GetChannel("/meta/handshake").AddListener(new Listener());

where Listener.cs is

public class Listener : IMessageListener {
public void OnMessage(IClientSessionChannel channel, IMessage message) {
Console.WriteLine(message.Json);
} }

I am not getting events on neither of channel.

xs2bharat commented 4 years ago

nvm. i figured it out. i had put above lines before this.bayeuxClient.Handshake();

nahoj28 commented 3 years ago

@Rajat-Jindal - see the steps below

  1. Create a bayeuxclient by passing salesforce accesstoken and url
  2. once bayeuxclient created, add an event listener for handshake channel like below bayeuxClient.getChannel("/meta/handshake").addListener(handshakeListener); where handshakeListener is an event listener (HandShakeChannelListener)
  3. on success event of handshakeListener, you subscribe to pushtopics

Hi @guruprasad83 , I've the same issue, I'm reviewing this issues and I've the following doubts, this is my use case I've have an app to handle the connection to multiple channels of the same instance (channel1, channel2, ...channelN), the connection to each channel happens by demand, it means depends of the user actions, so currently I've a bayeuxClient by Channel.

So,

My apologizes, I'm a little confused with this.

Thanks