-
-
Save op-ct/47fa0c1d75c4b71a6bb52bcfd90269c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'eventmachine' | |
require 'em-ssh' | |
require 'amqp' | |
EM.run do | |
Signal.trap("INT") do | |
EM.stop | |
end | |
AMQP.connect(:host => 'localhost') do |amqp_conn| | |
amqp_ch = AMQP::Channel.new(amqp_conn) | |
amqp_ex = amqp_ch.fanout("gerrit.event") | |
amqp_ch.queue("test").bind(amqp_ex) | |
EM::Ssh.start('localhostt', 'testuser', :port => 29418) do |connection| | |
connection.errback do |err| | |
$stderr.puts "#{err} (#{err.class})" | |
end | |
connection.callback do |session| | |
session.exec('gerrit stream-events') do |channel, stream, data| | |
channel.on_data do |ch, data| | |
str = %Q({"host":"localhost","port":"29418","user":"hudsonslave","event":#{data.strip}}) | |
amqp_ex.publish(str) | |
$stdout.puts str | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'amqp' | |
require 'eventmachine' | |
EM.run do | |
AMQP.connect(:host => "localhost") do |conn| | |
ch = AMQP::Channel.new(conn) | |
ch.queue("test").subscribe do |payload| | |
puts "Received a message: #{payload}" | |
conn.close {EM.stop} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment