multiple_man 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multiple_man/connection.rb +10 -6
- data/lib/multiple_man/listener.rb +6 -6
- data/lib/multiple_man/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7b860f3537f1110bf32aa9ace742b8f2d0651ea
|
4
|
+
data.tar.gz: 03cd81f5720b7223df677a225a1ccd95c21892be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd8f4562f017be6be225faea4cc2ee96bc2606322cbdf3c21193892a5974e24323a5da05bc6ad9e11ef0c1e1eff83cd08eccea6ed0b6b1d109961d73e4e488d
|
7
|
+
data.tar.gz: 0c886d543a4216146680e025d4920370519925c87acf6ffd3ab734a0db032b79f2ac7508d0d14e35ad662762ab3e9a238c014f78608475f28ae512659d40365d
|
@@ -1,14 +1,18 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
|
1
3
|
module MultipleMan
|
2
4
|
class Connection
|
3
5
|
def self.connect
|
4
6
|
MultipleMan.logger.info "Connecting to #{MultipleMan.configuration.connection}"
|
5
7
|
connection = Bunny.new(MultipleMan.configuration.connection)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
begin
|
9
|
+
MultipleMan.logger.info "Starting connection"
|
10
|
+
connection.start
|
11
|
+
yield new(connection) if block_given?
|
12
|
+
ensure
|
13
|
+
MultipleMan.logger.info "Closing connection"
|
14
|
+
connection.close
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def initialize(connection)
|
@@ -5,7 +5,7 @@ module MultipleMan
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def start(connection)
|
8
|
-
|
8
|
+
MultipleMan.logger.info "Starting listeners."
|
9
9
|
self.connection = connection
|
10
10
|
ModelSubscriber.subscriptions.each do |subscription|
|
11
11
|
new(subscription).listen
|
@@ -22,21 +22,21 @@ module MultipleMan
|
|
22
22
|
attr_accessor :subscription
|
23
23
|
|
24
24
|
def listen
|
25
|
-
|
25
|
+
MultipleMan.logger.info "Listening for #{subscription.klass} with routing key #{subscription.routing_key}."
|
26
26
|
queue.bind(connection.topic, routing_key: subscription.routing_key).subscribe do |delivery_info, meta_data, payload|
|
27
27
|
process_message(delivery_info, payload)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def process_message(delivery_info, payload)
|
32
|
-
|
32
|
+
MultipleMan.logger.info "Processing message for #{delivery_info.routing_key}."
|
33
33
|
begin
|
34
34
|
operation = delivery_info.routing_key.split(".").last
|
35
|
-
subscription.send(operation, JSON.parse(payload))
|
35
|
+
subscription.send(operation, JSON.parse(payload).with_indifferent_access)
|
36
36
|
rescue Exception => ex
|
37
|
-
|
37
|
+
MultipleMan.logger.error " Error - #{ex.message}"
|
38
38
|
end
|
39
|
-
|
39
|
+
MultipleMan.logger.info " Successfully processed!"
|
40
40
|
end
|
41
41
|
|
42
42
|
def queue
|
data/lib/multiple_man/version.rb
CHANGED