Search code examples
salesforcecometdbayeux

Cometd/bayeux client + salesforce streaming API issue


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

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.

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 the 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.

In my client I am using cometd from - https://github.com/couchand/CometD.NET/tree/headers and for push topics subscription I am using this - https://github.com/foluis/Salesforce_PushTopics

Any help would be greatly appreciated.


Solution

  • Ok finally I could able to get this working. Below are the changes

    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 is what cometd does, its a default behavior)
    3. So, the solution is, we always need to do channel subscription inside "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.