Ruby AMQP 未初始化常量错误

发布于 2024-09-02 23:00:21 字数 1121 浏览 3 评论 0原文

我正在尝试这段代码(来自此处的在线文章:http://www.randomhacks.net/articles/2009/05/08/chat-c​​lient-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

但最终出现以下错误:

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

之后,我在我的开发环境中使用 AMQP 尝试了不同的示例代码,但所有代码都显示了该错误。所以问题不在代码中,问题出在我的开发环境中。任何人都可以指出我的开发环境的问题吗?提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有心的人 2024-09-09 23:00:21

我安装了 AMQP 并与 Ruby 集成(通过 bunny gem)。也许我可以帮忙?

最有可能的是 gem 安装无法编译 amqp 库。卸载 gem 并重新安装,仔细查看生成的消息。可能您只是缺少一些第三方库。

你在哪个平台?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文