h1. About Bunny is a synchronous "AMQP":http://bit.ly/hw2ELX client. It supports Ruby 1.9.2, 1.8.7, Ruby Enterprise Edition and JRuby. Protocol-wise, Bunny supports AMQP 0.9.1 and 0.8. Support for AMQP 0.8 will be dropped in the next version of Bunny (0.7) because most of popular AMQP brokers such as RabbitMQ already stopped or planning to stop supporting it in the near future. Bunny is based on a great deal of useful code from the "amqp Ruby gem":http://github.com/ruby-amqp/amqp and "Carrot":http://github.com/famoseagle/carrot. You can use Bunny to: * Create and delete exchanges * Create and delete queues * Publish and consume messages h1. Differences from Official Gem We have added two things to the gem: * the ability to unsubscribe from a queue once the queue is empty (unreliable) * the ability to break out of a subscription loop if a condition has been met h1. Quick Start
require "bunny" b = Bunny.new(:logging => true) # start a communication session with the amqp server b.start b.qos # must be enabled for rpc features to work # declare a queue q = b.queue("test1") e = b.exchange('') correlation_id = 123 # publish a message to the queue e.publish("Junk", :key => q.name, :correlation_id => 0) e.publish("Junk", :key => q.name, :correlation_id => 1) e.publish("Hello everybody!", :key => q.name, :correlation_id => correlation_id) e.publish("Junk", :key => q.name, :correlation_id => 2) expected_msg = nil # get message from the queue q.subscribe(:ack => true) do |msg| if msg[:header].properties[:correlation_id].to_i == correlation_id expected_msg = msg[:payload] msg[:subscribed] = false end end puts "This is the correct message: " + expected_msg + "\n\n" # close the connection b.stop... or just:
require "bunny" # Create a direct queue named "my_testq" Bunny.run { |c| c.queue("my_testq") }Please see the @examples@ directory for additional usage information. h2. Intended Use # Generate a correlation_id # Send a message to the queue with the correlation_id set # Subscribe to the reply queue # Process messages until you get the correlation_id you want # tell the subscription you are no longer interested in messages h1. Links * "Source code":http://github.com/sparqcode/bunny * "@rubyamqp":http://twitter.com/rubyamqp at Twitter * "Ruby AMQP Google Group":http://groups.google.com/group/ruby-amqp * "Blog":http://bunnyamqp.wordpress.com