Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6618585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:51:13+00:00 2026-05-25T20:51:13+00:00

Some background: Gerrit exposes an event stream through SSH . It’s a cute trick,

  • 0

Some background: Gerrit exposes an event stream through SSH. It’s a cute trick, but I need to convert those events into AMQP messages. I’ve tried to do this with ruby-amqp and Net::SSH but, well, it doesn’t seem as if the AMQP sub-component is even being run at all.

I’m fairly new to EventMachine. Can someone point out what I am doing incorrectly? The answer to “Multiple servers in a single EventMachine reactor) didn’t seem applicable. The program, also available in a gist for easier access, is:

#!/usr/bin/env ruby                                                                                                                                            

require 'rubygems'
require 'optparse'
require 'net/ssh'
require 'json'
require 'yaml'
require 'amqp'
require 'logger'

trap(:INT) { puts; exit }

options = {
  :logs => 'kili.log',
  :amqp => {
    :host => 'localhost',
    :port => '5672',
  },
  :ssh => {
    :host => 'localhost',
    :port => '22',
    :user => 'nobody',
    :keys => '~/.ssh/id_rsa',
  }
}
optparse = OptionParser.new do|opts|
  opts.banner = "Usage: kili [options]"
  opts.on( '--amqp_host HOST', 'The AMQP host kili will connect to.') do |a|
    options[:amqp][:host] = a
  end
  opts.on( '--amqp_port PORT', 'The port for the AMQP host.') do |ap|
    options[:amqp][:port] = ap
  end
  opts.on( '--ssh_host HOST', 'The SSH host kili will connect to.') do |s|
    options[:ssh][:host] = s
  end
  opts.on( '--ssh_port PORT', 'The SSH port kili will connect on.') do |sp|
    options[:ssh][:port] = sp
  end
  opts.on( '--ssh_keys KEYS', 'Comma delimeted SSH keys for user.') do |sk|
    options[:ssh][:keys] = sk
  end
  opts.on( '--ssh_user USER', 'SSH user for host.') do |su|
    options[:ssh][:user] = su
  end
  opts.on( '-l', '--log LOG', 'The log location of Kili') do |log|
    options[:logs] = log
  end
  opts.on( '-h', '--help', 'Display this screen' ) do
    puts opts
    exit
  end
end


optparse.parse!
log = Logger.new(options[:logs])
log.level = Logger::INFO

amqp = options[:amqp]
sshd = options[:ssh]
queue= EM::Queue.new

EventMachine.run do

  AMQP.connect(:host => amqp[:host], :port => amqp[:port]) do |connection|
    log.info "Connected to AMQP at #{amqp[:host]}:#{amqp[:port]}"
    channel = AMQP::Channel.new(connection)
    exchange = channel.topic("traut", :auto_delete => true)

    queue.pop do |msg|
      log.info("Pulled #{msg} out of queue.")
      exchange.publish(msg[:data], :routing_key => msg[:route]) do
        log.info("On route #{msg[:route]} published:\n#{msg[:data]}")
      end
    end
  end


  Net::SSH.start(sshd[:host], sshd[:user],
    :port => sshd[:port], :keys => sshd[:keys].split(',')) do |ssh|
    log.info "SSH connection to #{sshd[:host]}:#{sshd[:port]} as #{sshd[:user]} made."

    channel = ssh.open_channel do |ch|
      ch.exec "gerrit stream-events" do |ch, success|
        abort "could not stream gerrit events" unless success

        # "on_data" is called when the process writes something to                                                                                             
        # stdout                                                                                                                                               
        ch.on_data do |c, data|
          json = JSON.parse(data)
          if json['type'] == 'change-merged'
            project = json['change']['project']
            route = "com.carepilot.event.code.review.#{project}"
            msg = {:data => data, :route => route}
            queue.push(msg)
            log.info("Pushed #{msg} into queue.")
          else
            log.info("Ignoring event of type #{json['type']}")
          end
        end


    # "on_extended_data" is called when the process writes                                                                                                 
    # something to stderr                                                                                                                                  
    ch.on_extended_data do |c, type, data|
          log.error(data)
    end

    ch.on_close { log.info('Connection closed') }
      end
    end  
  end  

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:51:13+00:00Added an answer on May 25, 2026 at 8:51 pm

    Net::SSH is not asynchronous, so your EventMachine.run() is never reaching the end of the block, thus never resuming the reactor thread. This causes the AMQP code to never start. I would suggest running your SSH code within another thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some background: We have some entity classes need to be serialized, so we implement
Some background: If I wanted to use for, for instance, scanf() to convert a
Some background: I am making a raycaster, well... was making. But I decided to
Some background info; LanguageResource is the base class LanguageTranslatorResource and LanguageEditorResource inherit from LanguageResource
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
Some background I'm currently working on a mobile site so I keep switching user
Some background: My job involves maintaining a large multi-threaded multi-process C++ / C# application,
Some Background to begin: I've implemented a custom MembershipProvider that validates a user from
Some background: we have a windows application (c#) that locate in the system try.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.