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

Cometd/bayeux client + salesforce streaming API issue #23

Closed
guruprasad83 opened this issue May 16, 2018 · 7 comments
Closed

Cometd/bayeux client + salesforce streaming API issue #23

guruprasad83 opened this issue May 16, 2018 · 7 comments

Comments

@guruprasad83
Copy link

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
Copy link

ohaucke commented May 19, 2018

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

#3 (comment)

@guruprasad83
Copy link
Author

@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
Copy link

@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
Copy link
Author

@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
Copy link

xs2bharat commented Jul 3, 2020

@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
Copy link

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

@ohaucke ohaucke mentioned this issue Jul 13, 2020
@nahoj28
Copy link

nahoj28 commented Jul 16, 2021

@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,

  • Should I subscribe to /meta/handshake by each bayeuxclient?
  • After apply the previous step, then in the On event of the HandsShakeListener I should subscribe to the channels, so there is not need the step mentioned in Reconnection issue #3 (comment) ?

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

Thanks

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

5 participants