Skip to content

Instantly share code, notes, and snippets.

@krishna-shilpakar
Created March 24, 2014 08:30
Show Gist options
  • Save krishna-shilpakar/9736370 to your computer and use it in GitHub Desktop.
Save krishna-shilpakar/9736370 to your computer and use it in GitHub Desktop.
require "amqp"
EventMachine.run do
connection = AMQP.connect
channel = AMQP::Channel.new(connection)
requests_queue = channel.queue("citizen40.install.app", :exclusive => true, :auto_delete => true)
requests_queue.subscribe(:ack => true) do |metadata, payload|
puts "[requests] Got a request #{metadata.message_id}. Sending a reply..."
# codes that will install the softwares.
# For example
# shellout = "apt-get install #{data[:app]"
channel.default_exchange.publish("citizen40.install.app.acknowledge,
:routing_key => metadata.reply_to,
:correlation_id => metadata.message_id,
:mandatory => true)
metadata.ack
end
Signal.trap("INT") { connection.close { EventMachine.stop } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment