class Object
Public Instance Methods
initialize_consumers(rabbitmq_host)
click to toggle source
Initialize all enabled consumners NOTE: this method will be replaced with a routine to reflect through all valid consumers and initialze them implicitly
# File lib/rabbithutch.rb, line 18 def initialize_consumers(rabbitmq_host) puts "Initializing Consumers for #{rabbitmq_host["displayname"]}" consumers = [] @config.consumers.each do |consumer| # if consumer["enabled"] == true case consumer["name"] when "console_consumer" consumers << RabbitHutch::ConsoleConsumer.new() when "mongo_consumer" consumers << RabbitHutch::MongoConsumer.new(rabbitmq_host, @config) when "log4r_consumer" consumers << RabbitHutch::Log4rConsumer.new(rabbitmq_host, @config) end end #end puts "\tdone" consumers end
start()
click to toggle source
Entry Point to the application, Begins queue listener and initializes all consmers
# File lib/rabbithutch.rb, line 55 def start begin EventMachine.run do @config.rabbitmq_hosts.each do |rabbitmq_host| if rabbitmq_host["enabled"] == true start_worker(rabbitmq_host) end end Signal.trap("INT"){EventMachine.stop} Signal.trap("QUIT"){EventMachine.stop} Signal.trap("TERM"){EventMachine.stop} Signal.trap("TSTP"){EventMachine.stop} end rescue Exception=>e puts "#{e.message} #{e.backtrace}" end end
start_service()
click to toggle source
The Service controller.
# File lib/rabbithutchservice.rb, line 5 def start_service begin puts "-------------------------" puts "Starting RabbitHutch #1" Daemons.run(File.dirname(__FILE__) + '/rabbithutch.rb') rescue SystemExit=>e puts e.inspect rescue Exception=>e puts e.inspect end end
start_worker(rabbitmq_host)
click to toggle source
Start the worker process to listen to a RabbitMq Node
# File lib/rabbithutch.rb, line 38 def start_worker(rabbitmq_host) displayname = rabbitmq_host["displayname"] hostname = rabbitmq_host["hostname"] username = rabbitmq_host["username"] password = rabbitmq_host["password"] consumers = initialize_consumers(rabbitmq_host) puts "Listening to RabbitMq #{displayname}, host: #{hostname}, username #{username}, password #{password}" AMQP.connect(:host => hostname, :user => username, :password => password) do |connection| channel = AMQP::Channel.new(connection) worker = RabbitHutch::Worker.new(channel, @config, consumers) worker.start end end