rabbithutch 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- require_relative '../lib/rabbithutchservice.rb'
1
+ require_relative '../lib/rabbithutchservice.rb'
@@ -1 +1 @@
1
- require_relative '../lib/rabbithutchmgr.rb'
1
+ require_relative '../lib/rabbithutchmgr.rb'
@@ -0,0 +1,5 @@
1
+ puts "============================="
2
+ puts "== Launching the rabbithutch web manager"
3
+ puts ">> Open the URL below to administer the rabbithutch service"
4
+ web_location = File.dirname(__FILE__) + '/../web/rabbithutchweb.rb'
5
+ system "shotgun #{web_location}"
@@ -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_
@@ -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_
@@ -0,0 +1 @@
1
+ hi
@@ -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
+
@@ -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
@@ -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