Rails how to parse text/event-stream? Rails how to parse text/event-stream? ruby ruby

Rails how to parse text/event-stream?


Set a timer to check source.ready_state, it seems like it does not connect to api for some reason

EDIT: it seems your problem is in https' SNI, which is not supported by current eventmachine release, so upon connecting eventsource tries to connect to default virtual host on api machine, not the one the api is on, thus the CONNECTING state

Try using eventmachine from master branch, it already states to have support for SNI, that is going to be released in 1.2.0:

gem 'eventmachine', github:'eventmachine/eventmachine'


require 'eventmachine'require 'em-http'require 'json'http = EM::HttpRequest.new("api_url", :keepalive => true, :connect_timeout => 0, :inactivity_timeout => 0)EventMachine.run do  s = http.get({'accept' => 'application/json'})  s.stream do |data|    puts data  endend

I used EventMachine http libary.