AMQP::Queue#initialize - undefined method `queue' for nil:NilClass #121

Closed
eranb opened this Issue Feb 15, 2012 · 5 comments

Comments

Projects
None yet
2 participants

eranb commented Feb 15, 2012

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
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)
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:
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

/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 <main>'
    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 <class:EventMachineClient>'
    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 `<main>'
Owner

michaelklishin commented Feb 15, 2012

The whole idea of using :nowait with a block is contradictory. There is no queue.declare-ok method (because you instructed RabbitMQ to not send it) to yield.

Owner

michaelklishin commented Feb 15, 2012

Should be fixed in b2e76cc. Can you use bundler's :git feature or you need 0.9.4 to be released soon? Is tomorrow OK?

eranb commented Feb 15, 2012

Verified the fix, working as expected.

Thanks a lot.

eranb commented Feb 15, 2012

Sure NP, I will wait for 0.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment