dafiti-rabbit-hutch 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/web/rabbithutchweb.rb +106 -0
- metadata +2 -11
- data/lib/configurator.rb +0 -38
- data/lib/consumer.rb +0 -32
- data/lib/consumers/console_consumer.rb +0 -21
- data/lib/consumers/log4r_consumer.rb +0 -36
- data/lib/consumers/mongo_consumer.rb +0 -35
- data/lib/logger.rb +0 -16
- data/lib/rabbithutch.rb +0 -78
- data/lib/rabbithutchmgr.rb +0 -48
- data/lib/rabbithutchservice.rb +0 -18
- data/lib/worker.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b744707fbf0a08c3516948d2755b8d73c9bf5677f93c8c519489f4265c327dc
|
4
|
+
data.tar.gz: d943b769c98a9bc4c9d0c4d70e589037f56dc9d25dba1c29da7c4acfe610dd35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e08d0c24abae122426dfb7a7c302927e8196684039e33f741442dd43d4cb588d7f367feb41be97a37cdb2e8ad226337f11a50c3e444610ff9148bfe6ee94363
|
7
|
+
data.tar.gz: 5cfc3f9e1f49c9451ece540bf088e4b77fcdb055282f86bbb363db1d1b11345e854184ad8f5d903d76ccdf1264463fa99afaf2b73b835db29d68f02555413f14
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'haml'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module RabbitHutchWeb
|
6
|
+
class RabbitSettings
|
7
|
+
|
8
|
+
attr_accessor :settings, :application, :rabbitmq_hosts, :consumers
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
file = File.dirname(__FILE__) + '/../config.yaml'
|
12
|
+
@settings = YAML::load(File.open(file))
|
13
|
+
@application = settings['application']
|
14
|
+
@rabbitmq_hosts = settings['rabbitmq']['hosts']
|
15
|
+
@consumers = settings['consumers_config']['consumers']
|
16
|
+
end
|
17
|
+
|
18
|
+
def save
|
19
|
+
file = File.dirname(__FILE__) + '/../config.yaml'
|
20
|
+
File.open(file, "w") do|f|
|
21
|
+
f.write self.settings.to_yaml
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse(data)
|
26
|
+
@settings = YAML::load(data)
|
27
|
+
@application = settings['application']
|
28
|
+
@rabbitmq_hosts = settings['rabbitmq']['hosts']
|
29
|
+
@consumers = settings['consumers_config']['consumers']
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
get '/' do
|
36
|
+
settings = RabbitHutchWeb::RabbitSettings.new
|
37
|
+
|
38
|
+
haml :index, :locals => {
|
39
|
+
:app => settings.application,
|
40
|
+
:rabbit => settings.rabbitmq_hosts,
|
41
|
+
:consumers => settings.consumers
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/rabbitmqsettings/add' do
|
46
|
+
settings = RabbitHutchWeb::RabbitSettings.new
|
47
|
+
params["id"] = settings.rabbitmq_hosts.length + 1
|
48
|
+
haml :rabbitmqsettings, :locals=>{:settings=>params}
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/rabbitmqsettings/edit/:id' do |id|
|
52
|
+
setting = nil
|
53
|
+
settings = RabbitHutchWeb::RabbitSettings.new
|
54
|
+
settings.rabbitmq_hosts.each{|item| setting = item if item["id"]==id.to_i }
|
55
|
+
haml :rabbitmqsettings, :locals=>{:settings=>setting}
|
56
|
+
end
|
57
|
+
|
58
|
+
post '/rabbitmqsettings/save' do
|
59
|
+
exists = false
|
60
|
+
settings = RabbitHutchWeb::RabbitSettings.new
|
61
|
+
settings.rabbitmq_hosts.each{|item|
|
62
|
+
if item["id"]==params["id"].to_i
|
63
|
+
item["displayname"] = params["displayname"]
|
64
|
+
item["enabled"] = params["enabled"]
|
65
|
+
item["hostname"] = params["hostname"]
|
66
|
+
item["username"] = params["username"]
|
67
|
+
item["password"] = params["password"]
|
68
|
+
exists = true
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
unless exists
|
73
|
+
setting =
|
74
|
+
{
|
75
|
+
"id" => params["id"],
|
76
|
+
"displayname" => params["displayname"],
|
77
|
+
"enabled" => params["enabled"],
|
78
|
+
"hostname" => params["hostname"],
|
79
|
+
"username" => params["username"],
|
80
|
+
"password" => params["password"]
|
81
|
+
}
|
82
|
+
settings.rabbitmq_hosts << setting
|
83
|
+
end
|
84
|
+
|
85
|
+
settings.save
|
86
|
+
redirect "/"
|
87
|
+
end
|
88
|
+
|
89
|
+
post '/rabbitmqsettings/delete' do
|
90
|
+
redirect "/"
|
91
|
+
end
|
92
|
+
|
93
|
+
get '/manageconfig' do
|
94
|
+
haml :manageconfig, :locals=>{:data=>params}
|
95
|
+
end
|
96
|
+
|
97
|
+
post '/manageconfig' do
|
98
|
+
haml :manageconfig, :locals=>{:data=>params}
|
99
|
+
end
|
100
|
+
|
101
|
+
post '/manageconfig/save' do
|
102
|
+
settings = RabbitHutchWeb::RabbitSettings.new
|
103
|
+
settings.parse(params["filetext"])
|
104
|
+
settings.save
|
105
|
+
redirect "/"
|
106
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dafiti-rabbit-hutch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luiz Bartolomeu
|
@@ -248,16 +248,7 @@ files:
|
|
248
248
|
- README.md
|
249
249
|
- bin/rabbithutch
|
250
250
|
- bin/rabbithutchweb
|
251
|
-
-
|
252
|
-
- lib/consumer.rb
|
253
|
-
- lib/consumers/console_consumer.rb
|
254
|
-
- lib/consumers/log4r_consumer.rb
|
255
|
-
- lib/consumers/mongo_consumer.rb
|
256
|
-
- lib/logger.rb
|
257
|
-
- lib/rabbithutch.rb
|
258
|
-
- lib/rabbithutchmgr.rb
|
259
|
-
- lib/rabbithutchservice.rb
|
260
|
-
- lib/worker.rb
|
251
|
+
- web/rabbithutchweb.rb
|
261
252
|
homepage: https://rubygems.org/gems/example
|
262
253
|
licenses:
|
263
254
|
- MIT
|
data/lib/configurator.rb
DELETED
@@ -1,38 +0,0 @@
|
|
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
DELETED
@@ -1,32 +0,0 @@
|
|
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
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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 "console"
|
15
|
-
puts item
|
16
|
-
rescue Exception => e
|
17
|
-
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,36 +0,0 @@
|
|
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
|
-
puts "log_consumer"
|
29
|
-
@logger.info(item)
|
30
|
-
rescue Exception => e
|
31
|
-
puts "Error occurred Message Handler trying to write messages to Log #{e.inspect}"
|
32
|
-
#@log.error("Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,35 +0,0 @@
|
|
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
|
-
puts "mongo"
|
27
|
-
db = @connection.db(@database)
|
28
|
-
coll = db.collection(item[:exchange])
|
29
|
-
coll.insert(item)
|
30
|
-
rescue Exception => e
|
31
|
-
puts "Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/logger.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|
data/lib/rabbithutch.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "amqp"
|
3
|
-
require_relative "configurator"
|
4
|
-
require_relative "consumers/mongo_consumer"
|
5
|
-
require_relative "consumers/log4r_consumer"
|
6
|
-
require_relative "consumers/console_consumer"
|
7
|
-
require_relative "worker"
|
8
|
-
|
9
|
-
@config = RabbitHutch::Configurator.new({})
|
10
|
-
|
11
|
-
puts "\tEnvironment Settings"
|
12
|
-
@config.rabbitmq_hosts.each do |rabbitmq_host|
|
13
|
-
puts "\tDisplay Name: #{rabbitmq_host["displayname"]}, host: #{rabbitmq_host["hostname"]}, username: #{rabbitmq_host["username"]}, enabled #{rabbitmq_host["enabled"]}"
|
14
|
-
end
|
15
|
-
|
16
|
-
# Initialize all enabled consumners
|
17
|
-
# NOTE: this method will be replaced with a routine to reflect through all valid consumers and initialze them implicitly
|
18
|
-
def initialize_consumers(rabbitmq_host)
|
19
|
-
puts "Initializing Consumers for #{rabbitmq_host["displayname"]}"
|
20
|
-
consumers = []
|
21
|
-
@config.consumers.each do |consumer|
|
22
|
-
# if consumer["enabled"] == true
|
23
|
-
case consumer["name"]
|
24
|
-
when "console_consumer"
|
25
|
-
consumers << RabbitHutch::ConsoleConsumer.new()
|
26
|
-
when "mongo_consumer"
|
27
|
-
consumers << RabbitHutch::MongoConsumer.new(rabbitmq_host, @config)
|
28
|
-
when "log4r_consumer"
|
29
|
-
consumers << RabbitHutch::Log4rConsumer.new(rabbitmq_host, @config)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
#end
|
33
|
-
puts "\tdone"
|
34
|
-
consumers
|
35
|
-
end
|
36
|
-
|
37
|
-
# Start the worker process to listen to a RabbitMq Node
|
38
|
-
def start_worker(rabbitmq_host)
|
39
|
-
displayname = rabbitmq_host["displayname"]
|
40
|
-
hostname = rabbitmq_host["hostname"]
|
41
|
-
username = rabbitmq_host["username"]
|
42
|
-
password = rabbitmq_host["password"]
|
43
|
-
|
44
|
-
consumers = initialize_consumers(rabbitmq_host)
|
45
|
-
|
46
|
-
puts "Listening to RabbitMq #{displayname}, host: #{hostname}, username #{username}"
|
47
|
-
AMQP.connect(:host => hostname, :user => username, :password => password) do |connection|
|
48
|
-
channel = AMQP::Channel.new(connection)
|
49
|
-
worker = RabbitHutch::Worker.new(channel, @config, consumers)
|
50
|
-
worker.start
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Entry Point to the application, Begins queue listener and initializes all consmers
|
55
|
-
def start
|
56
|
-
begin
|
57
|
-
EventMachine.run do
|
58
|
-
|
59
|
-
@config.rabbitmq_hosts.each do |rabbitmq_host|
|
60
|
-
if rabbitmq_host["enabled"] == true
|
61
|
-
start_worker(rabbitmq_host)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
Signal.trap("INT"){EventMachine.stop}
|
65
|
-
Signal.trap("QUIT"){EventMachine.stop}
|
66
|
-
Signal.trap("TERM"){EventMachine.stop}
|
67
|
-
Signal.trap("TSTP"){EventMachine.stop}
|
68
|
-
end
|
69
|
-
rescue Exception=>e
|
70
|
-
puts "#{e.message} #{e.backtrace}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Kick off the App
|
75
|
-
start
|
76
|
-
|
77
|
-
|
78
|
-
|
data/lib/rabbithutchmgr.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'mustache'
|
3
|
-
require_relative 'configurator.rb'
|
4
|
-
|
5
|
-
module RabbitHutch
|
6
|
-
#This class controls the Command Line Interface
|
7
|
-
class CLI < Thor
|
8
|
-
|
9
|
-
StandardTemplate =<<-TEMPLATE
|
10
|
-
{{#config}}
|
11
|
-
|
12
|
-
{{#application}}
|
13
|
-
Application
|
14
|
-
+------------------------+------------------------+
|
15
|
-
|Exchange |Queue |
|
16
|
-
+------------------------+------------------------+
|
17
|
-
|{{exchangename}} | {{queuename}} |
|
18
|
-
+------------------------+------------------------+
|
19
|
-
{{/application}}
|
20
|
-
|
21
|
-
{{#rabbitmq}}
|
22
|
-
RabbitMq Servers
|
23
|
-
+------------------------+------------------------+
|
24
|
-
|Display Name |Host |
|
25
|
-
+------------------------+------------------------+
|
26
|
-
{{#hosts}}
|
27
|
-
|{{displayname}} | {{hostname}} |
|
28
|
-
+------------------------+------------------------+
|
29
|
-
{{/hosts}}
|
30
|
-
{{/rabbitmq}}
|
31
|
-
|
32
|
-
{{/config}}
|
33
|
-
TEMPLATE
|
34
|
-
|
35
|
-
desc "list", "List all config settings"
|
36
|
-
#method_option :errors, :aliases => "-e", :type => :boolean, :default => false, :desc => "true = display files that could not be processed, false = do not display skipped files"
|
37
|
-
#method_option :hashtype, :aliases => "-h", :default => "cmd5", :desc => "Choose the hash algorithm to use - md5 or sha"
|
38
|
-
method_option :config, :aliases => "-c", :default => nil, :desc => "parse the config file from a specified location "
|
39
|
-
#method_option :recursive, :aliases => "-r", :type => :boolean, :default => "false", :desc => "true = recurse through sub directories, false = only do top directory"
|
40
|
-
def list()
|
41
|
-
@config = RabbitHutch::Configurator.new(options)
|
42
|
-
puts Mustache.render(StandardTemplate, :config => @config);
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
CLI.start()
|
48
|
-
end
|
data/lib/rabbithutchservice.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'daemons'
|
3
|
-
|
4
|
-
# The Service controller.
|
5
|
-
def start_service
|
6
|
-
begin
|
7
|
-
puts "-------------------------"
|
8
|
-
puts "Starting RabbitHutch #1"
|
9
|
-
Daemons.run(File.dirname(__FILE__) + '/rabbithutch.rb')
|
10
|
-
rescue SystemExit=>e
|
11
|
-
puts e.inspect
|
12
|
-
rescue Exception=>e
|
13
|
-
puts e.inspect
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
start_service()
|
18
|
-
|
data/lib/worker.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "amqp"
|
3
|
-
require_relative "configurator"
|
4
|
-
require_relative "consumer"
|
5
|
-
|
6
|
-
module RabbitHutch
|
7
|
-
@exchange_name = "amq.rabbitmq.trace"
|
8
|
-
|
9
|
-
class Worker
|
10
|
-
|
11
|
-
def initialize(channel, config, consumers)
|
12
|
-
@channel = channel
|
13
|
-
@channel.on_error(&method(:handle_channel_exception))
|
14
|
-
@consumer = Consumer.new(consumers)
|
15
|
-
@exchange_name = config.application['exchangename']
|
16
|
-
@queue_name = config.application['queuename']
|
17
|
-
end
|
18
|
-
|
19
|
-
# begin listening for all topics in publish.#
|
20
|
-
def start
|
21
|
-
@exchange = @channel.topic(@exchange_name, :durable => true, :auto_delete => false, :internal => true)
|
22
|
-
@queue = @channel.queue(@queue_name, :durable => true, :auto_delete => false)
|
23
|
-
@queue.bind(@exchange, :routing_key => 'publish.#')
|
24
|
-
@queue.subscribe(&@consumer.method(:handle_message))
|
25
|
-
end
|
26
|
-
|
27
|
-
def handle_channel_exception(channel, channel_close)
|
28
|
-
puts "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}"
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|