0
按照本教程(http://arfon.org/twitter-streaming-with-eventmachine-and-dynamodb)嘗試啓動Amazon監聽環境。接收特定的推文並將它們添加到一個Dynamo數據庫(通過一個新線程)。在spawn_threadpool中使用Eventmachine gem - > block
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'HERE IT IS'
AWS_SECRET_KEY = 'YES HERE'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
table.load_schema
TweetStream.configure do |config|
config.username = 'geezlouis'
config.password = 'password'
config.auth_method = :basic
end
EM.run{
client = TweetStream::Client.new
def write_to_dynamo(status)
EM.defer do
tweet_hash = {:user_id => status.user.id,
:created_at => status.created_at,
:id => status.id,
:screen_name => status.user.screen_name}
begin
table.items.create(tweet_hash)
rescue Exception => e
puts e.message
puts e.backtrace.inspect
end
end
end
client.track("Romney", "Gingrich") do |status|
write_to_dynamo(status)
end
}
未定義的局部變量或方法'表「主:對象
["tweets.rb:31:in `block in write_to_dynamo'", "/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in
call'", "/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in
塊spawn_threadpool」」使用EventMachine的時候產卵線程我碰到下面的一切工作但罰款]
我想我錯過了什麼 - >看起來像我提交的確切粘貼。 – 2012-03-30 22:51:41