Asynchronous HTTP requests with ruby

Discussion in 'Ruby' started by Eki, Feb 19, 2012.

  1. Eki

    Eki Guest

    I have a rabbitmq queue full of requests and I want to send the
    requests as an HTTP GET/POST asynchronously, without the need to wait
    for each request response. now I'm confused of what is better to use,
    threads or just EM ? The way i'm using it at the moment is something
    like the following , but it would be great to know if there is any
    better implementation with better performance here since it is a very
    crucial part of the program :

    AMQP.start:)host => "localhost") do |connection|
    queue = MQ.queue("some_queue")
    queue.subscribe do |body|
    EventMachine::HttpRequest.new('http://localhost:9292/').post :body
    => {:message => body.to_json }
    end
    end

    With the code above, is the system will wait for each request to
    finish before starting the next one ? and if there any tips here I
    would highly appreciate it
     
    Eki, Feb 19, 2012
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.