Skip to content

Instantly share code, notes, and snippets.

@BrindleFly
Created February 12, 2013 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrindleFly/4770532 to your computer and use it in GitHub Desktop.
Save BrindleFly/4770532 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'bunny'
conn = Bunny.new
conn.start
channel = conn.create_channel
queue = channel.queue("app.work", :durable=>true)
# Create exchange for rpc response and bind to temp queue
conn.exchange("app_rpc_response", :type=>:direct)
callback_queue = conn.queue("", :auto_delete => true, :exclusive => true)
callback_queue.bind("app_rpc_response", :routing_key => callback_queue.name)
# Send request to standard work queue
queue.publish "exec_sample_rpc", :headers=>{:foo=>"bar"}, :reply_to => callback_queue.name
# Wait for reponse. Note: if I sleep until message put on queue by producer, it works; if not, returns empty
delivery_info, properties, payload = callback_queue.pop(:block=>true)
puts "#{delivery_info}, #{properties}, #{payload}"
conn.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment