Simultaneous HTTP connect with EventMachine

S

Shea Barton

Can anyone give many any tips about how to have multiple
EventMachine.connect instances running at the same time? I thought
em-synchrony looked promising, but it only works with
EventMachine::HttpRequest.

I need EventMachine.connect because my application streams http data
using the receive_data callback, which EventMachine::HttpRequest lacks.

If I try running more than one streaming EventMachine.connect normally
inside EM.run, I only see the results of the last EventMachine.connect

help?
 
K

Kirk Haines

Can anyone give many any tips about how to have multiple
EventMachine.connect instances running at the same time? I thought
em-synchrony looked promising, but it only works with
EventMachine::HttpRequest.

I need EventMachine.connect because my application streams http data
using the receive_data callback, which EventMachine::HttpRequest lacks.

If I try running more than one streaming EventMachine.connect normally
inside EM.run, I only see the results of the last EventMachine.connect

You are doing something wrong.

EM.connect, just like everything else in EM, is asynchronous. You can
connect to many places at the same time. I've done tests with 20000
connections before.

As for receive_data, all connection handlers have a receive_data,
since that is what EM calls when it receives a chunk of data. If the
handler descends from EventMachine::Connection, it will have a default
receive_data defined for it.

However:

https://github.com/eventmachine/em-http-request/blob/master/lib/em-http/client.rb#L226

You need to provide more details about what you are doing before
anyone is going to be able to tell you what you are doing wrong.


Kirk Haines
Software Developer
Engine Yard
 
S

Shea Barton

More details:

Im trying to use Twitter::JSONStream, which is an
EventMachine::Connection to simultaneously watch two different twitter
filters using the streaming API.

gem 'twitter-stream'

require 'twitter/json_stream'
EM.run do
a = Twitter::JSONStream.connect :path =>
"/1/statuses/filter.json?track=:)", :auth => "username:password"
b = Twitter::JSONStream.connect :path =>
"/1/statuses/filter.json?track=:(", :auth => "username:password"

a.each_item {puts "happy" }
b.each_item {puts "unhappy" }

end

This should be printing alternating happy and unhappy, but right now it
only prints one of the two

This is my first time actually using EventMachine. thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top