rabbithutch 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +24 -24
- data/Gemfile +4 -4
- data/Gemfile.lock +68 -55
- data/LICENSE.txt +21 -21
- data/README.md +137 -107
- data/bin/rabbithutch +1 -1
- data/bin/rabbithutchmgr +1 -1
- data/bin/rabbithutchweb +5 -0
- data/config.yaml +32 -32
- data/config/config.yaml +32 -0
- data/index.html +1 -0
- data/lib/configurator.rb +38 -38
- data/lib/consumer.rb +31 -31
- data/lib/consumers/console_consumer.rb +20 -20
- data/lib/consumers/log4r_consumer.rb +35 -35
- data/lib/consumers/mongo_consumer.rb +34 -34
- data/lib/logger.rb +16 -16
- data/lib/rabbithutch.rb +78 -78
- data/lib/rabbithutchmgr.rb +47 -47
- data/lib/worker.rb +32 -32
- data/rabbithutch.gemspec +43 -37
- data/rabbithutchservice.rb +18 -18
- data/rakefile +5 -5
- data/web/public/assets/css/bootstrap-responsive.css +1092 -0
- data/web/public/assets/css/bootstrap-responsive.min.css +9 -0
- data/web/public/assets/css/bootstrap.css +6046 -0
- data/web/public/assets/css/bootstrap.min.css +9 -0
- data/web/public/assets/css/main.css +30 -0
- data/web/public/assets/img/glyphicons-halflings-white.png +0 -0
- data/web/public/assets/img/glyphicons-halflings.png +0 -0
- data/web/public/assets/js/bootstrap.js +2159 -0
- data/web/public/assets/js/bootstrap.min.js +6 -0
- data/web/rabbithutchweb.rb +13 -0
- data/web/views/index.haml +26 -0
- data/web/views/layout.haml +66 -0
- metadata +170 -29
data/bin/rabbithutch
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative '../lib/rabbithutchservice.rb'
|
1
|
+
require_relative '../lib/rabbithutchservice.rb'
|
data/bin/rabbithutchmgr
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative '../lib/rabbithutchmgr.rb'
|
1
|
+
require_relative '../lib/rabbithutchmgr.rb'
|
data/bin/rabbithutchweb
ADDED
data/config.yaml
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
application:
|
2
|
-
exchangename: amq.rabbitmq.trace
|
3
|
-
queuename: rabbithutch
|
4
|
-
|
5
|
-
rabbitmq:
|
6
|
-
hosts:
|
7
|
-
- displayname: localserver
|
8
|
-
enabled: true
|
9
|
-
hostname: 127.0.0.1
|
10
|
-
username: guest
|
11
|
-
password: guest
|
12
|
-
- displayname: anotherserver
|
13
|
-
enabled: false
|
14
|
-
hostname: 127.0.0.2
|
15
|
-
username: guest
|
16
|
-
password: guest
|
17
|
-
|
18
|
-
consumers_config:
|
19
|
-
consumers:
|
20
|
-
- name: console_consumer
|
21
|
-
enabled: true
|
22
|
-
- name: mongo_consumer
|
23
|
-
enabled: true
|
24
|
-
hostname: 127.0.0.1
|
25
|
-
username: guest
|
26
|
-
password: guest
|
27
|
-
database_prefix: rhutch_
|
28
|
-
port: 27017
|
29
|
-
- name: log4r_consumer
|
30
|
-
enabled: true
|
31
|
-
log_location: /tmp
|
32
|
-
log_prefix: rhutch_
|
1
|
+
application:
|
2
|
+
exchangename: amq.rabbitmq.trace
|
3
|
+
queuename: rabbithutch
|
4
|
+
|
5
|
+
rabbitmq:
|
6
|
+
hosts:
|
7
|
+
- displayname: localserver
|
8
|
+
enabled: true
|
9
|
+
hostname: 127.0.0.1
|
10
|
+
username: guest
|
11
|
+
password: guest
|
12
|
+
- displayname: anotherserver
|
13
|
+
enabled: false
|
14
|
+
hostname: 127.0.0.2
|
15
|
+
username: guest
|
16
|
+
password: guest
|
17
|
+
|
18
|
+
consumers_config:
|
19
|
+
consumers:
|
20
|
+
- name: console_consumer
|
21
|
+
enabled: true
|
22
|
+
- name: mongo_consumer
|
23
|
+
enabled: true
|
24
|
+
hostname: 127.0.0.1
|
25
|
+
username: guest
|
26
|
+
password: guest
|
27
|
+
database_prefix: rhutch_
|
28
|
+
port: 27017
|
29
|
+
- name: log4r_consumer
|
30
|
+
enabled: true
|
31
|
+
log_location: /tmp
|
32
|
+
log_prefix: rhutch_
|
data/config/config.yaml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
application:
|
2
|
+
exchangename: amq.rabbitmq.trace
|
3
|
+
queuename: rabbithutch
|
4
|
+
|
5
|
+
rabbitmq:
|
6
|
+
hosts:
|
7
|
+
- displayname: localserver
|
8
|
+
enabled: true
|
9
|
+
hostname: 127.0.0.1
|
10
|
+
username: guest
|
11
|
+
password: guest
|
12
|
+
- displayname: anotherserver
|
13
|
+
enabled: false
|
14
|
+
hostname: 127.0.0.2
|
15
|
+
username: guest
|
16
|
+
password: guest
|
17
|
+
|
18
|
+
consumers_config:
|
19
|
+
consumers:
|
20
|
+
- name: console_consumer
|
21
|
+
enabled: true
|
22
|
+
- name: mongo_consumer
|
23
|
+
enabled: true
|
24
|
+
hostname: 127.0.0.1
|
25
|
+
username: guest
|
26
|
+
password: guest
|
27
|
+
database_prefix: rhutch_
|
28
|
+
port: 27017
|
29
|
+
- name: log4r_consumer
|
30
|
+
enabled: true
|
31
|
+
log_location: /tmp
|
32
|
+
log_prefix: rhutch_
|
data/index.html
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hi
|
data/lib/configurator.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module RabbitHutch
|
4
|
-
class Configurator
|
5
|
-
|
6
|
-
attr_accessor :config
|
7
|
-
|
8
|
-
def initialize options
|
9
|
-
|
10
|
-
file = options['config'] || (File.dirname(__FILE__) + '/../config.yaml')
|
11
|
-
|
12
|
-
puts "Using config from #{file}"
|
13
|
-
|
14
|
-
unless File.exists? file
|
15
|
-
raise "Configuration file [#{file}] doesn't exist"
|
16
|
-
end
|
17
|
-
@config = YAML::load(File.open(file))
|
18
|
-
end
|
19
|
-
|
20
|
-
def application
|
21
|
-
@config['application']
|
22
|
-
end
|
23
|
-
|
24
|
-
def log_config
|
25
|
-
@config['log4r_config']
|
26
|
-
end
|
27
|
-
|
28
|
-
def consumers
|
29
|
-
@config['consumers_config']["consumers"]
|
30
|
-
end
|
31
|
-
|
32
|
-
def rabbitmq_hosts
|
33
|
-
@config['rabbitmq']['hosts']
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module RabbitHutch
|
4
|
+
class Configurator
|
5
|
+
|
6
|
+
attr_accessor :config
|
7
|
+
|
8
|
+
def initialize options
|
9
|
+
|
10
|
+
file = options['config'] || (File.dirname(__FILE__) + '/../config.yaml')
|
11
|
+
|
12
|
+
puts "Using config from #{file}"
|
13
|
+
|
14
|
+
unless File.exists? file
|
15
|
+
raise "Configuration file [#{file}] doesn't exist"
|
16
|
+
end
|
17
|
+
@config = YAML::load(File.open(file))
|
18
|
+
end
|
19
|
+
|
20
|
+
def application
|
21
|
+
@config['application']
|
22
|
+
end
|
23
|
+
|
24
|
+
def log_config
|
25
|
+
@config['log4r_config']
|
26
|
+
end
|
27
|
+
|
28
|
+
def consumers
|
29
|
+
@config['consumers_config']["consumers"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def rabbitmq_hosts
|
33
|
+
@config['rabbitmq']['hosts']
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/lib/consumer.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require_relative "configurator"
|
3
|
-
require_relative "consumers/mongo_consumer"
|
4
|
-
|
5
|
-
module RabbitHutch
|
6
|
-
# Controls the consumers that are to be kicked off based on the config file
|
7
|
-
class Consumer
|
8
|
-
def initialize(consumers)
|
9
|
-
@consumers = consumers
|
10
|
-
end
|
11
|
-
|
12
|
-
# Raised on receipt of a message from RabbitMq and uses the appropriate appender
|
13
|
-
def handle_message(metadata, payload)
|
14
|
-
# loop through appenders and fire each as required
|
15
|
-
@consumers.each do |consumer|
|
16
|
-
action = metadata.routing_key.split('.', 2).first
|
17
|
-
if(action == "publish")
|
18
|
-
exchange = metadata.attributes[:headers]["exchange_name"]
|
19
|
-
queue = metadata.routing_key.split('.', 2).last
|
20
|
-
item = {:date => Time.now,
|
21
|
-
:exchange => exchange,
|
22
|
-
:queue => queue,
|
23
|
-
:routing_keys => metadata.attributes[:headers]["routing_keys"].inspect,
|
24
|
-
:attributes => metadata.attributes.inspect,
|
25
|
-
:payload => payload.inspect
|
26
|
-
}
|
27
|
-
consumer.log_event(item)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require "rubygems"
|
2
|
+
require_relative "configurator"
|
3
|
+
require_relative "consumers/mongo_consumer"
|
4
|
+
|
5
|
+
module RabbitHutch
|
6
|
+
# Controls the consumers that are to be kicked off based on the config file
|
7
|
+
class Consumer
|
8
|
+
def initialize(consumers)
|
9
|
+
@consumers = consumers
|
10
|
+
end
|
11
|
+
|
12
|
+
# Raised on receipt of a message from RabbitMq and uses the appropriate appender
|
13
|
+
def handle_message(metadata, payload)
|
14
|
+
# loop through appenders and fire each as required
|
15
|
+
@consumers.each do |consumer|
|
16
|
+
action = metadata.routing_key.split('.', 2).first
|
17
|
+
if(action == "publish")
|
18
|
+
exchange = metadata.attributes[:headers]["exchange_name"]
|
19
|
+
queue = metadata.routing_key.split('.', 2).last
|
20
|
+
item = {:date => Time.now,
|
21
|
+
:exchange => exchange,
|
22
|
+
:queue => queue,
|
23
|
+
:routing_keys => metadata.attributes[:headers]["routing_keys"].inspect,
|
24
|
+
:attributes => metadata.attributes.inspect,
|
25
|
+
:payload => payload.inspect
|
26
|
+
}
|
27
|
+
consumer.log_event(item)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require "mongo"
|
4
|
-
|
5
|
-
module RabbitHutch
|
6
|
-
class ConsoleConsumer
|
7
|
-
|
8
|
-
def initialize()
|
9
|
-
puts "\tInitializing Console Consumer"
|
10
|
-
end
|
11
|
-
|
12
|
-
def log_event(item)
|
13
|
-
begin
|
14
|
-
puts item
|
15
|
-
rescue Exception => e
|
16
|
-
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require "mongo"
|
4
|
+
|
5
|
+
module RabbitHutch
|
6
|
+
class ConsoleConsumer
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
puts "\tInitializing Console Consumer"
|
10
|
+
end
|
11
|
+
|
12
|
+
def log_event(item)
|
13
|
+
begin
|
14
|
+
puts item
|
15
|
+
rescue Exception => e
|
16
|
+
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'log4r'
|
4
|
-
#require 'log4r/outputter/syslogoutputter'
|
5
|
-
|
6
|
-
module RabbitHutch
|
7
|
-
class Log4rConsumer
|
8
|
-
|
9
|
-
def initialize(rabbitmq_host, config)
|
10
|
-
puts "\tInitializing Log4r Consumer"
|
11
|
-
@rabbitmq_host = rabbitmq_host
|
12
|
-
@config = config
|
13
|
-
@log_name = rabbitmq_host["displayname"]
|
14
|
-
@config.consumers.each do |consumer|
|
15
|
-
if consumer["name"] == 'log4r_consumer'
|
16
|
-
@log_prefix = consumer['log_prefix']
|
17
|
-
@log_location = consumer['log_location']
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
@logger = Log4r::Logger.new("#{@log_name}#_log")
|
23
|
-
@logger.outputters << Log4r::FileOutputter.new("#{@log_name}_filelog", :filename => "#{@log_location}/#{@log_prefix}#{@log_name}.log")
|
24
|
-
end
|
25
|
-
|
26
|
-
def log_event(item)
|
27
|
-
begin
|
28
|
-
@logger.info(item)
|
29
|
-
rescue Exception => e
|
30
|
-
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
31
|
-
#@log.error("Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'log4r'
|
4
|
+
#require 'log4r/outputter/syslogoutputter'
|
5
|
+
|
6
|
+
module RabbitHutch
|
7
|
+
class Log4rConsumer
|
8
|
+
|
9
|
+
def initialize(rabbitmq_host, config)
|
10
|
+
puts "\tInitializing Log4r Consumer"
|
11
|
+
@rabbitmq_host = rabbitmq_host
|
12
|
+
@config = config
|
13
|
+
@log_name = rabbitmq_host["displayname"]
|
14
|
+
@config.consumers.each do |consumer|
|
15
|
+
if consumer["name"] == 'log4r_consumer'
|
16
|
+
@log_prefix = consumer['log_prefix']
|
17
|
+
@log_location = consumer['log_location']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
@logger = Log4r::Logger.new("#{@log_name}#_log")
|
23
|
+
@logger.outputters << Log4r::FileOutputter.new("#{@log_name}_filelog", :filename => "#{@log_location}/#{@log_prefix}#{@log_name}.log")
|
24
|
+
end
|
25
|
+
|
26
|
+
def log_event(item)
|
27
|
+
begin
|
28
|
+
@logger.info(item)
|
29
|
+
rescue Exception => e
|
30
|
+
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
31
|
+
#@log.error("Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require "mongo"
|
4
|
-
|
5
|
-
module RabbitHutch
|
6
|
-
class MongoConsumer
|
7
|
-
|
8
|
-
def initialize(rabbitmq_host, config)
|
9
|
-
puts "\tInitializing MongoDb Consumer"
|
10
|
-
@config = config
|
11
|
-
@rabbitmq_host = rabbitmq_host
|
12
|
-
|
13
|
-
@config.consumers.each do |consumer|
|
14
|
-
if consumer["name"] == 'mongo_consumer'
|
15
|
-
@host = consumer['hostname']
|
16
|
-
@port = consumer["port"]
|
17
|
-
@database_prefix = consumer['database_prefix']
|
18
|
-
@database = "#{@database_prefix}#{rabbitmq_host["displayname"]}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
@connection = Mongo::Connection.new(@host, @port)
|
22
|
-
end
|
23
|
-
|
24
|
-
def log_event(item)
|
25
|
-
begin
|
26
|
-
db = @connection.db(@database)
|
27
|
-
coll = db.collection(item[:exchange])
|
28
|
-
coll.insert(item)
|
29
|
-
rescue Exception => e
|
30
|
-
puts "Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require "mongo"
|
4
|
+
|
5
|
+
module RabbitHutch
|
6
|
+
class MongoConsumer
|
7
|
+
|
8
|
+
def initialize(rabbitmq_host, config)
|
9
|
+
puts "\tInitializing MongoDb Consumer"
|
10
|
+
@config = config
|
11
|
+
@rabbitmq_host = rabbitmq_host
|
12
|
+
|
13
|
+
@config.consumers.each do |consumer|
|
14
|
+
if consumer["name"] == 'mongo_consumer'
|
15
|
+
@host = consumer['hostname']
|
16
|
+
@port = consumer["port"]
|
17
|
+
@database_prefix = consumer['database_prefix']
|
18
|
+
@database = "#{@database_prefix}#{rabbitmq_host["displayname"]}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@connection = Mongo::Connection.new(@host, @port)
|
22
|
+
end
|
23
|
+
|
24
|
+
def log_event(item)
|
25
|
+
begin
|
26
|
+
db = @connection.db(@database)
|
27
|
+
coll = db.collection(item[:exchange])
|
28
|
+
coll.insert(item)
|
29
|
+
rescue Exception => e
|
30
|
+
puts "Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/logger.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
require 'log4r/yamlconfigurator'
|
3
|
-
require 'log4r/outputter/syslogoutputter'
|
4
|
-
|
5
|
-
class Logger
|
6
|
-
@@log = nil
|
7
|
-
def self.init(config)
|
8
|
-
if !@@log.nil?
|
9
|
-
return @@log
|
10
|
-
end
|
11
|
-
|
12
|
-
configurator = Log4r::YamlConfigurator
|
13
|
-
configurator.decode_yaml config.log_config
|
14
|
-
@@log = Log4r::Logger['main']
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'log4r'
|
2
|
+
require 'log4r/yamlconfigurator'
|
3
|
+
require 'log4r/outputter/syslogoutputter'
|
4
|
+
|
5
|
+
class Logger
|
6
|
+
@@log = nil
|
7
|
+
def self.init(config)
|
8
|
+
if !@@log.nil?
|
9
|
+
return @@log
|
10
|
+
end
|
11
|
+
|
12
|
+
configurator = Log4r::YamlConfigurator
|
13
|
+
configurator.decode_yaml config.log_config
|
14
|
+
@@log = Log4r::Logger['main']
|
15
|
+
end
|
16
|
+
end
|