ruby-amqp/amqp — Issue #121: AMQP::Queue#initialize - undefined method `queue' for nil:NilClass
Author: eranb
Created: 2012-02-15 16:02:15+00:00
State: open

When creating new queue object from AMQP::Channel object, using the channel.queue() method and passing it a block, NoMethodError thrown in AMQP::Queue#initialize method.

* Inside AMQP::Channel#queue, new proc object is created that takes two parameters (q,method) and passing it AMQP::Queue#initialize

```ruby
shim = Proc.new { |q, method|
queue = find_queue(method.queue)
if block.arity == 1
block.call(queue)
else
block.call(queue, method.consumer_count, method.message_count)
end
}
Queue.new(self, name, opts, &shim)
# https://github.com/ruby-amqp/amqp/blob/master/lib/amqp/channel.rb#L830:L838
```

* Inside AMQP::Queue#initialize the block is called only with one argument (instead of two)

```ruby
if @opts[:nowait]
@status = :opened
block.call(self) if block
else
@status = :opening
end
# https://github.com/ruby-amqp/amqp/blob/master/lib/amqp/queue.rb#L188:L193
```

* Example:

```ruby
require 'amqp'
require 'amqp/extensions/rabbitmq'
AMQP.start(:host => 'rabbitmq',:user => 'guest',:pass => 'guest',:vhost => '/') do |connection|
channel = AMQP::Channel.new(connection)
channel.queue("shuki_q",{:nowait => true,:passive=>false, :auto_delete=>false, :arguments=>{"x-expires"=>5600000}}) do |queue|
queue.bind('raw.shuki',:routing_key => 'ShukiesTukies')
puts "before subscribe"
queue.subscribe(:ack => true) do |header, payload|
puts "inside subscribe"
p header.class
end
end
end
```

### Output
```bash
/Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/channel.rb:831:in `block in queue!': undefined method `queue' for nil:NilClass (NoMethodError)
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/queue.rb:192:in `call'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/queue.rb:192:in `initialize'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/channel.rb:838:in `new'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/channel.rb:838:in `queue!'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/channel.rb:814:in `queue'
from delme.rb:6:in `block in

'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapters/event_machine.rb:132:in `call'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapters/event_machine.rb:132:in `block in register_connection_callback'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `call'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `set_deferred_status'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/eventmachine-0.12.10/lib/em/deferrable.rb:173:in `succeed'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapters/event_machine.rb:338:in `connection_successful'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapter.rb:616:in `handle_open_ok'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapters/event_machine.rb:386:in `block in '
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapter.rb:539:in `call'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapter.rb:539:in `receive_frameset'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapter.rb:519:in `receive_frame'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amq-client-0.9.2/lib/amq/client/async/adapters/event_machine.rb:327:in `receive_data'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from /Users/eran/.rvm/gems/ruby-1.9.2-p290@graphite-workers/gems/amqp-0.9.3/lib/amqp/connection.rb:38:in `start'
from delme.rb:4:in `

'
```