Ruby AMQP 未初始化常量错误
我正在尝试这段代码(来自此处的在线文章: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
但最终出现以下错误:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我安装了 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?