Created
February 12, 2013 15:14
-
-
Save BrindleFly/4770532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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