How to test for asynchronous HTTP requests in ruby using EventMachine -



How to test for asynchronous HTTP requests in ruby using EventMachine -

i'm getting messages of rabbitmq queue , each message url want create request to. i'm using amqp gem subscribe queue , uses eventmachine, i'm using the em-http-request library create http requests. according documentation here: https://github.com/igrigorik/em-http-request/wiki/parallel-requests next issue asynchronous http-requests:

eventmachine.run { http1 = eventmachine::httprequest.new('http://google.com/').get http2 = eventmachine::httprequest.new('http://yahoo.com/').get http1.callback { } http2.callback { } end

so when subscribe rabbitmq queue have next code:

x = 0 eventmachine.run connection = amqp.connect(:host => '127.0.0.1') channel = amqp::channel.new(connection) channel.prefetch(50) queue = channel.queue("http.requests") exchange = channel.direct("") queue.subscribe |metadata, payload| url = payload.inspect eval " @http#{x} = eventmachine::httprequest.new(url).get @http#{x}.callback puts \"got response\" puts @http#{x}.response end x = x+1 " end end

this dynamically creates new variables , creates new http requests, similar way described in em-http-request documentation. there way test whether requests beingness made asynchronously? possible write console every time request fired off can see fired off 1 after other without waiting response?

you can seek running tcpdump , analysing output. if see tcp three-way handshakes 2 connections beingness interleaved connections happening in parallel.

this can't part of automated test though, if that's you're trying aim for. happy verify library says 1 time , not create part of test suite.

ruby-on-rails asynchronous rabbitmq eventmachine em-http-request

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -