ruby-amqp/bunny — Issue #37: Cannot call Queue#status while inside subscribe block
Author: gorsuch
Created: 2012-02-12 19:01:28+00:00
State: open

I'm using ruby 1.9.2p290 with Bunny 0.7.9.

This is my sample code:

```ruby
require 'bunny'

STDOUT.sync = true

client = Bunny.new(ENV["RABBITMQ_URL"])
client.start

e = client.exchange('data', type: :topic, durable: true)
q = Bunny::Queue.new(client, 'simple_persister', durable: true)
q.bind(e, key: 'hello.*')

2.times do
e.publish("hello", key: "hello.world")
end

q.subscribe(act: true) do |msg|
p [:debug, q.status]
end

```

Upon execution, I see:

```ruby
/Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/bunny/queue08.rb:303:in `status': undefined method `message_count' for # (NoMethodError)
from pub.rb:17:in `block in

'
from /Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/qrack/subscription.rb:81:in `call'
from /Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/qrack/subscription.rb:81:in `block in start'
from /Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/qrack/subscription.rb:56:in `loop'
from /Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/qrack/subscription.rb:56:in `start'
from /Users/mgorsuch/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/bunny-0.7.9/lib/bunny/queue08.rb:311:in `subscribe'
from pub.rb:16:in `

'
```

If I change `2.times` to `1.times`, it works as expected.

Am I doing it wrong?