Permalink
Browse files

Merge pull request #2 from nel/master

Make it work with latest version of AMQP
  • Loading branch information...
rubenfonseca committed Aug 7, 2012
2 parents b4640b0 + bf58ce6 commit 2ea3282fa7b8665563348a0bd3e841e101895028
Showing with 24 additions and 19 deletions.
  1. +2 −0 .gitignore
  2. +8 −6 socket.rb
  3. +14 −13 twitterfeed.rb
View
@@ -1,3 +1,5 @@
bin
vendor
.bundle
+Gemfile.lock
+.rbenv-version
View
@@ -1,17 +1,19 @@
-require 'vendor/gems/environment'
require 'em-websocket'
require 'uuid'
-require 'mq'
+require 'amqp'
uuid = UUID.new
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen do
puts "WebSocket opened"
-
- twitter = MQ.new
- twitter.queue(uuid.generate).bind(twitter.fanout('twitter')).subscribe do |t|
- ws.send t
+ AMQP.connect(:host => '127.0.0.1') do |connection, open_ok|
+ AMQP::Channel.new(connection) do |channel, open_ok|
+ channel.queue(uuid.generate, :auto_delete => true).bind(channel.fanout("twitter")).subscribe do |t|
+ puts 'got a tweet'
+ ws.send t
+ end
+ end
end
end
View
@@ -1,20 +1,21 @@
-require 'vendor/gems/environment'
-require 'mq'
+require 'amqp'
require 'twitter/json_stream'
username = ARGV.shift
password = ARGV.shift
raise "need username and password" if !username or !password
-AMQP.start(:host => 'localhost') do
- twitter = MQ.new.fanout('twitter')
-
- stream = Twitter::JSONStream.connect(
- :path => '/1/statuses/filter.json?track=iphone',
- :auth => "#{username}:#{password}"
- )
-
- stream.each_item do |status|
- twitter.publish(status)
+AMQP.start(:host => 'localhost') do |connection, open_ok|
+ AMQP::Channel.new(connection) do |channel, open_ok|
+ twitter = channel.fanout("twitter")
+
+ stream = Twitter::JSONStream.connect(
+ :path => '/1/statuses/filter.json?track=iphone',
+ :auth => "#{username}:#{password}"
+ )
+
+ stream.each_item do |status|
+ twitter.publish(status)
+ end
end
-end
+end

0 comments on commit 2ea3282

Please sign in to comment.