restforce: Problems using the Streaming API through restforce

I am having some difficulties using the Streaming API through restforce. I have created a PushTopic, and am using restforce to connect to it. The first couple of steps of the connection setup seem to be going great, up until the ‘/meta/connect’ call after which I always get a “402::Unknown client” error back. I have pasted my Faye debug output below, as you can see it keeps creating new client ids, which are the invalidated. BTW I have connected to the topic through Workbench, and that works like a charm.

For whatever reason I feel it has to do with Restforce / Faye not resending cookies in subsequent requests. But that hung is pretty much unfounded. Has anybody else used the Streaming stuff in restforce lately?

My restforce code is straight from the README and looks like this:

#Preceded by authentication and stuff
EM.run {
  client.subscribe 'AllAccounts' do |message|
    puts message.inspect
  end
}

Faye debug output:

"[Faye::Client] Closed connection for nil"
"[Faye::Client] Initiating handshake with https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Selected \"long-polling\" transport for https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/handshake\",\"version\":\"1.0\",\"supportedConnectionTypes\":[\"long-polling\"],\"id\":\"g\"}"
"[Faye::Transport::Http] Client nil sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/handshake\",\"version\":\"1.0\",\"supportedConnectionTypes\":[\"long-polling\"],\"id\":\"g\"}"
"[Faye::Transport::Http] Client nil received from https://na15.salesforce.com/cometd/29.0: [{\"channel\":\"/meta/handshake\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"version\":\"1.0\",\"successful\":true,\"minimumVersion\":\"1.0\",\"id\":\"g\",\"supportedConnectionTypes\":[\"long-polling\"]}]"
"[Faye::Client] Passing through incoming extensions: {\"channel\":\"/meta/handshake\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"version\":\"1.0\",\"successful\":true,\"minimumVersion\":\"1.0\",\"id\":\"g\",\"supportedConnectionTypes\":[\"long-polling\"]}"
"[Faye::Client] Selected \"long-polling\" transport for https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Handshake successful: \"1kugm77rxeg9szd1uv8f3b07hayi\""
"[Faye::Client] Calling deferred actions for \"1kugm77rxeg9szd1uv8f3b07hayi\""
"[Faye::Client] Client \"1kugm77rxeg9szd1uv8f3b07hayi\" attempting to subscribe to \"/topic/AllAccounts\""
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/subscribe\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"subscription\":\"/topic/AllAccounts\",\"id\":\"h\"}"
"[Faye::Transport::Http] Client \"1kugm77rxeg9szd1uv8f3b07hayi\" sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/subscribe\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"subscription\":\"/topic/AllAccounts\",\"id\":\"h\"}"
"[Faye::Client] Initiating connection for \"1kugm77rxeg9szd1uv8f3b07hayi\""
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/connect\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"connectionType\":\"long-polling\",\"id\":\"i\"}"
"[Faye::Transport::Http] Client \"1kugm77rxeg9szd1uv8f3b07hayi\" sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/connect\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"connectionType\":\"long-polling\",\"id\":\"i\"}"
"[Faye::Client] Calling deferred actions for \"1kugm77rxeg9szd1uv8f3b07hayi\""
"[Faye::Transport::Http] Client \"1kugm77rxeg9szd1uv8f3b07hayi\" received from https://na15.salesforce.com/cometd/29.0: [{\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"error\":\"402::Unknown client\",\"successful\":false},{\"channel\":\"/meta/connect\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"advice\":{\"reconnect\":\"handshake\",\"interval\":500},\"error\":\"402::Unknown client\",\"successful\":false,\"id\":\"i\"}]"
"[Faye::Client] Passing through incoming extensions: {\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"error\":\"402::Unknown client\",\"successful\":false}"
"[Faye::Client] Passing through incoming extensions: {\"channel\":\"/meta/connect\",\"clientId\":\"1kugm77rxeg9szd1uv8f3b07hayi\",\"advice\":{\"reconnect\":\"handshake\",\"interval\":500},\"error\":\"402::Unknown client\",\"successful\":false,\"id\":\"i\"}"
"[Faye::Client] Closed connection for nil"
"[Faye::Client] Initiating handshake with https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Selected \"long-polling\" transport for https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/handshake\",\"version\":\"1.0\",\"supportedConnectionTypes\":[\"long-polling\"],\"id\":\"j\"}"
"[Faye::Transport::Http] Client nil sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/handshake\",\"version\":\"1.0\",\"supportedConnectionTypes\":[\"long-polling\"],\"id\":\"j\"}"
"[Faye::Transport::Http] Client nil received from https://na15.salesforce.com/cometd/29.0: [{\"channel\":\"/meta/handshake\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"version\":\"1.0\",\"successful\":true,\"minimumVersion\":\"1.0\",\"id\":\"j\",\"supportedConnectionTypes\":[\"long-polling\"]}]"
"[Faye::Client] Passing through incoming extensions: {\"channel\":\"/meta/handshake\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"version\":\"1.0\",\"successful\":true,\"minimumVersion\":\"1.0\",\"id\":\"j\",\"supportedConnectionTypes\":[\"long-polling\"]}"
"[Faye::Client] Selected \"long-polling\" transport for https://na15.salesforce.com/cometd/29.0"
"[Faye::Client] Handshake successful: \"1ipm4iptdi6yy2g1ujts9tbm5ghv\""
"[Faye::Client] Calling deferred actions for \"1ipm4iptdi6yy2g1ujts9tbm5ghv\""
"[Faye::Client] Client \"1ipm4iptdi6yy2g1ujts9tbm5ghv\" attempting to subscribe to \"/topic/AllAccounts\""
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/subscribe\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"subscription\":\"/topic/AllAccounts\",\"id\":\"k\"}"
"[Faye::Transport::Http] Client \"1ipm4iptdi6yy2g1ujts9tbm5ghv\" sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/subscribe\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"subscription\":\"/topic/AllAccounts\",\"id\":\"k\"}"
"[Faye::Client] Initiating connection for \"1ipm4iptdi6yy2g1ujts9tbm5ghv\""
"[Faye::Client] Passing through outgoing extensions: {\"channel\":\"/meta/connect\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"connectionType\":\"long-polling\",\"id\":\"l\"}"
"[Faye::Transport::Http] Client \"1ipm4iptdi6yy2g1ujts9tbm5ghv\" sending message to https://na15.salesforce.com/cometd/29.0: {\"channel\":\"/meta/connect\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"connectionType\":\"long-polling\",\"id\":\"l\"}"
"[Faye::Client] Calling deferred actions for \"1ipm4iptdi6yy2g1ujts9tbm5ghv\""
"[Faye::Transport::Http] Client \"1ipm4iptdi6yy2g1ujts9tbm5ghv\" received from https://na15.salesforce.com/cometd/29.0: [{\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"error\":\"402::Unknown client\",\"successful\":false},{\"channel\":\"/meta/connect\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"advice\":{\"reconnect\":\"handshake\",\"interval\":500},\"error\":\"402::Unknown client\",\"successful\":false,\"id\":\"l\"}]"
"[Faye::Client] Passing through incoming extensions: {\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"error\":\"402::Unknown client\",\"successful\":false}"
"[Faye::Client] Passing through incoming extensions: {\"channel\":\"/meta/connect\",\"clientId\":\"1ipm4iptdi6yy2g1ujts9tbm5ghv\",\"advice\":{\"reconnect\":\"handshake\",\"interval\":500},\"error\":\"402::Unknown client\",\"successful\":false,\"id\":\"l\"}"
"[Faye::Client] Closed connection for nil"
"[Faye::Client] Initiating handshake with https://na15.salesforce.com/cometd/29.0"

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

Thanks Aldoforce, i spent one whole day on this.

this is my code to help if anyone faces the same issue like me. Basically the idea is to use Faye::Client instead of restforce embedded client

This is placed in one of my rails 4.1.5 initializer

#gem “cookiejar”, :git => “https://github.com/MissionCapital/cookiejar.git” # this is actually not required. gem ‘restforce’ gem ‘faye’, ‘0.8.9’

Faye::Logging.log_level = :debug
Faye.logger = lambda { |m| puts m }

$sf = Restforce.new username: 'zenfelixdev1@gmail.com', password: 'omitted', client_id: 'omitted', client_secret: 'omitted'

credentials = $sf.authenticate!

server        = credentials.instance_url
topic         = 'WealthManagerUpdates'
access_token  = credentials.access_token
token_type    = 'OAuth'

client = Faye::Client.new("#{server}/cometd/31.0/")
client.set_header('Authorization', "#{token_type} #{access_token}")

Thread.abort_on_exception = true
Thread.new {
  EM.run do
    client.subscribe("/topic/#{topic}") do |message|
      puts message.inspect
    end
  end
}