Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
Queue#status should push the queue onto declare-ok 'wait list', fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Jul 19, 2011
1 parent 7624dc4 commit 5118012
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
13 changes: 6 additions & 7 deletions examples/issues/issue_94.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env ruby
# encoding: utf-8

if defined?(Bundler)
Bundler.setup
else
require "rubygems"
end
gem 'amqp', "0.7.2"
require "bundler"
Bundler.setup

$:.unshift(File.expand_path("../../../lib", __FILE__))

require "amqp"

puts "Running amqp gem #{AMQP::VERSION}"
Expand All @@ -16,7 +15,7 @@
exchange = channel.direct("")
queue = channel.queue("indexer_queue", { :durable => true })

EM.add_periodic_timer(5) {
EM.add_periodic_timer(1) {
queue.status do |num_messages, num_consumers|
puts "msgs:#{num_messages}"
end
Expand Down
1 change: 1 addition & 0 deletions lib/amqp/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def status(opts = {}, &blk)

@on_status = blk
@mq.callback {
@mq.queues_awaiting_declare_ok.push(self)
@mq.send Protocol::Queue::Declare.new({ :queue => name,
:passive => true }.merge(opts))
}
Expand Down
44 changes: 44 additions & 0 deletions spec/integration/queue_status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# encoding: utf-8

require 'spec_helper'

describe AMQP::Queue do

#
# Environment
#

include EventedSpec::AMQPSpec

default_timeout 5



#
# Examples
#

describe "#status" do
it "yields # of messages & consumers to the callback" do
events = []
channel = AMQP::Channel.new

queue1 = channel.queue("", :auto_delete => true)
queue2 = channel.queue("amqpgem.tests.a.named.queue", :auto_delete => true)

EventMachine.add_timer(1.0) do
queue1.status do |m, c|
events << :queue1_declare_ok
end
queue2.status do |m, c|
events << :queue2_declare_ok
end
end

done(2.0) {
events.should include(:queue1_declare_ok)
events.should include(:queue2_declare_ok)
}
end
end
end

0 comments on commit 5118012

Please sign in to comment.