0

I am working with this Ruby library (https://github.com/restforce/restforce#streaming) to connect to Salesforce's Platform Events.

Here is my code:

EM.run do
  client.subscribe '/event/My_Event', replay: -2 do |message|
    puts message.inspect
  end
end

I keep getting connection successful and not successful in quick succession:

{"advice"=>{"interval"=>0, "reconnect"=>"handshake"}, "channel"=>"/meta/connect", "id"=>"1x", "error"=>"403::Unknown client", "successful"=>false}
[COMETD UP]
{"ext"=>{"replay"=>true, "payload.format"=>true}, "minimumVersion"=>"1.0", "clientId"=>"xqp16hb2chcdsi58wg0sy23qfxfzd", "supportedConnectionTypes"=>["long-polling"], "channel"=>"/meta/handshake", "id"=>"1y", "version"=>"1.0", "successful"=>true}

There is a similar question on StackOverflow but that suggestion hasn't worked for me. I have also gone through this thread on the Salesforce Developer Forum on the error above.

And, after a minute, I get this:

{"clientId"=>"xhekc3efsx2nuz716v0p0wpf8ald", "error"=>"400::Client xhekc3efsx2nuz716v0p0wpf8ald has established a session, but no BAYEUX_BROWSER cookie present", "successful"=>false}

The only Github issue I found on the above error still has not been answered for almost 5 years.

I would appreciate any ideas. Thanks.

1

I am the CometD Project leader but I don't know the details of the SalesForce integration, so my answer may or may not apply.

When a CometD client first connects to a CometD server, it sends a handshake request. The server replies with a handshake reply and sends back a normal HTTP cookie called BAYEUX_BROWSER. Every subsequent message sent by the client must have this BAYEUX_BROWSER cookie sent back to the server. See this section and this section of the CometD documentation for further details.

My take is that the Ruby library that you are using may not process the cookies correctly and does not send back the BAYEUX_BROWSER cookie on the messages after the handshake.

| improve this answer | |
  • Thank you for your input. The library am using uses Faye (faye.jcoglan.com) to connect. My use case doesn't involve sending anything. I am just listening for events. Do I still need to send BAYEUX_BROWSER? – Muaad Sep 9 '19 at 18:29
  • Also, I keep getting this: {"advice"=>{"interval"=>0, "reconnect"=>"handshake"}, "channel"=>"/meta/connect", "id"=>"1x", "error"=>"403::Unknown client", "successful"=>false}. Is this a problem? – Muaad Sep 9 '19 at 18:50
  • OK. I have dug into the library code and was able to log what it sends back after the handshake. {"channel"=>"/meta/subscribe", "clientId"=>"zf93v5oevhr0k1pr462in7f15dg", "subscription"=>"/event/My_Event", "id"=>"2", "ext"=>{"replay"=>{"/event/My_Event"=>-2}}}. Does that look good? Am still getting the same error, btw. – Muaad Sep 9 '19 at 19:40
  • My comment about the cookie was more about the implementation details of the client library. I don't know Faye enough to help you here. "403::Unknown client" is a SalesForce message that says that the server can't find the correspondent session ID. You may have multiple errors due to multiple causes here, so I suggest that you first get it working with the official JavaScript, and only later try Ruby. – sbordet Sep 10 '19 at 11:53
  • Thanks for the clarifications @sbordet – Muaad Sep 12 '19 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.