xing / beetle

High Availability AMQP Messaging With Redundant Queues

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Beetle handlers should be able to do async work

joevandyk opened this issue · comments

Sample code:

client.register_handler(:search) do |m|
  query = m.data

  uri = "http://www.google.com/search?q=#{URI.encode(query)}"
  http = EM::HttpRequest.new(uri).get
  http.callback do |page|
    doc = Nokogiri::HTML(page.response)
    result = doc.css('h3.r a.l').map { |link| link.content }.to_json
    # I want to return result
    # Maybe something like
    # m.finished!(result)
  end
end

client.listen do
  puts "started google search server"
end

I made a sample project here: https://github.com/joevandyk/beetle-em/blob/em/server.rb (in the em branch).

So, ideally, a single RPC worker could handle multiple jobs at the same time that involve IO. My understanding is right now, a Beetle RPC handler has no way to do anything asynchronously.

your understanding is correct. not sure we really want to support callback style handlers at all.

This would require a major refactoring, if it even can be fitted to our current model.