spec/integration/coolio/basic_consume_spec.rb in amq-client-0.7.0.alpha35 vs spec/integration/coolio/basic_consume_spec.rb in amq-client-0.8.0
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: utf-8
+
require 'spec_helper'
require 'integration/coolio/spec_helper'
#
# Note that this spec doesn't test acknowledgements.
@@ -85,5 +87,61 @@
}
end
end # it "should not leave messages in the queues with noack=true"
end # context "sending 100 messages"
end # describe AMQ::Client::CoolioClient, "Basic.Consume"
+
+
+describe "Multiple", AMQ::Client::Async::Consumer, :nojruby => true do
+ include EventedSpec::SpecHelper
+ default_timeout 4
+
+ context "sharing the same queue with equal prefetch levels" do
+ let(:messages) { (0..99).map {|i| "Message #{i}" } }
+
+ it "have messages distributed to them in the round-robin manner" do
+ @consumer1_mailbox = []
+ @consumer2_mailbox = []
+ @consumer3_mailbox = []
+
+ coolio_amqp_connect do |client|
+ channel = AMQ::Client::Channel.new(client, 1)
+ channel.open do
+ queue = AMQ::Client::Queue.new(client, channel).declare(false, false, false, true)
+ queue.bind("amq.fanout")
+
+ consumer1 = AMQ::Client::Async::Consumer.new(channel, queue, "#{queue.name}-consumer-#{Time.now}")
+ consumer2 = AMQ::Client::Async::Consumer.new(channel, queue)
+ consumer3 = AMQ::Client::Async::Consumer.new(channel, queue, "#{queue.name}-consumer-#{rand}-#{Time.now}", false, true)
+
+
+ consumer1.consume.on_delivery do |method, header, payload|
+ @consumer1_mailbox << payload
+ end
+
+ consumer2.consume(true).on_delivery do |method, header, payload|
+ @consumer2_mailbox << payload
+ end
+
+ consumer3.consume(false) do
+ puts "Consumer 3 is ready"
+ end
+ consumer3.on_delivery do |method, header, payload|
+ @consumer3_mailbox << payload
+ end
+
+
+ exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
+ messages.each do |message|
+ exchange.publish(message)
+ end
+ end
+
+ done(1.5) {
+ @consumer1_mailbox.size.should == 34
+ @consumer2_mailbox.size.should == 33
+ @consumer3_mailbox.size.should == 33
+ }
+ end
+ end # it
+ end # context
+end # describe