开发者

Ruby AMQP uninitialized constant error

I was trying out this code (got from an online article here: http://www.randomhacks.net/articles/2009/05/08/chat-client-ruby-amqp-eventmachine-shoes)

require 'rubygems'
gem 'amqp'
require 'mq'

unless ARGV.length == 2
  STDERR.puts "Usage: #{$0}  "
  exit 1
end
$channel, $nick = ARGV

AMQP.start(:host => 'localhost') do
  $chat = MQ.topic('chat')

  # Print any messages on our channel.
  queue = MQ.queue($nick)
  queue.bind('chat', :key => $channel)
  queue.subscribe do |msg|
    if msg.index("#{$nick}:") != 0
      puts msg
    end
  end

  # Forward console input to our channel.
  module KeyboardInput
    include EM::Protocols::LineText2
    def receive_line data
      $chat.publish("#{$nick}: #{data}",
                    :开发者_运维技巧routing_key => $channel)
    end
  end
  EM.open_keyboard(KeyboardInput)
end

But ended up the following error:

chat.rb:11:in `': uninitialized constant AMQP (NameError)

After that, I tried different example code with AMQP at my dev env but all shows me that error. So the problem is not in the code, the problem with my dev env. Can anybody point me out the issues with my dev env. Thanks in advance.


I have AMQP installed and integrated with Ruby (via the bunny gem). Maybe I can help?

Most likely the gem install failed to compile the amqp libs. Uninstall the gem and reinstall, taking a very close look at the messages produced. Possibly you're only missing some third-party libs.

Which platform are you on?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜