MongoMapper,MongoDB和EventMachine
|
我正在使用DaemonKit创建AMQP侦听器。每当有消息通过网络时,我都希望将其记录到MongoDB。我已经将我的Rails MongoDB配置移了过来,并且连接正常。当我尝试创建新模型时,在Model.create方法中出现错误。
IOError when attempting to close socket connected to localhost:27017: #<IOError: closed stream>
/Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:856:in `rescue in send_message_on_socket\': Operation failed with the following exception: closed stream (Mongo::ConnectionFailure)
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:843:in `send_message_on_socket\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:483:in `block in receive_message\'
from <internal:prelude>:10:in `synchronize\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:482:in `receive_message\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:407:in `block in send_initial_query\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/connection.rb:609:in `instrument\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:406:in `send_initial_query\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:371:in `refresh\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:87:in `next_document\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:248:in `each\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:267:in `to_a\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/mongo-1.3.1/lib/mongo/cursor.rb:267:in `to_a\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/plucky-0.3.8/lib/plucky/query.rb:76:in `all\'
from /Volumes/External/Projects/ruby/alertsdaemons/eventmachine/libexec/eventmachine-daemon.rb:17:in `block in <top (required)>\'
from /Volumes/External/Projects/ruby/alertsdaemons/eventmachine/libexec/eventmachine-daemon.rb:15:in `loop\'
from /Volumes/External/Projects/ruby/alertsdaemons/eventmachine/libexec/eventmachine-daemon.rb:15:in `<top (required)>\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `block in require\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `block in load_dependency\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in `load_dependency\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/daemon-kit-0.1.8.2/lib/daemon_kit/application.rb:38:in `run\'
from /Users/lfaus/.rvm/gems/ruby-1.9.2-p180/gems/daemon-kit-0.1.8.2/lib/daemon_kit/application.rb:21:in `exec\'
from /Volumes/External/Projects/ruby/alertsdaemons/eventmachine/bin/eventmachine:12:in `<top (required)>\'
from -e:1:in `load\'
from -e:1:in `<main>\'
用于创建对象的代码:
# Sample loop to show process
loop do
DaemonKit.logger.info \"I\'m running\"
message = Message.create({
:first_name => \'Lee\',
:last_name => \'Faus\'
})
puts message.inspect
puts message.count
sleep 5
end
我读过我可以派生mongomapper来使http调用异步,但是这些错误似乎来自mongodb ruby驱动程序。任何帮助是极大的赞赏。
没有找到相关结果
已邀请:
1 个回复
恋卡
我不是mongomapper用户,所以我不知道如何翻译上面的示例。 我最好的建议是在pre-daemonization阶段对mongo进行“ ping”操作,并在失败的情况下出错,因此daemon甚至无法启动,并在post-daemonize配置中正确设置连接。