faye ruby client is not working

后端 未结 2 578
深忆病人
深忆病人 2021-02-04 20:58

I am using faye on my Rails 2.1 app. And after testing and fixing many things faye ruby client is not working.

This is my server code.

requi         


        
2条回答
  •  心在旅途
    2021-02-04 21:38

    You were almost there... You just needed to stop the EM event loop in your callbacks, like this:

    EM.run do
      client = Faye::Client.new('http://localhost:9292/faye')
      publication = client.publish("/faye/new_chats", {
        "user" => "ruby-logger",
        "message" => "Got your message!"
      })
      publication.callback do
        puts "[PUBLISH SUCCEEDED]"
        EM.stop_event_loop
      end
      publication.errback do |error|
        puts "[PUBLISH FAILED] #{error.inspect}"
        EM.stop_event_loop
      end
    end
    

提交回复
热议问题