Skip to content

Instantly share code, notes, and snippets.

@op-ct
Forked from rinrinne/gerrit-stream.rb
Created July 25, 2016 14:33
Show Gist options
  • Save op-ct/47fa0c1d75c4b71a6bb52bcfd90269c3 to your computer and use it in GitHub Desktop.
Save op-ct/47fa0c1d75c4b71a6bb52bcfd90269c3 to your computer and use it in GitHub Desktop.
#!/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
#!/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