bmc-daemon-lib 0.9.2 → 0.10.0
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/.gitignore +5 -0
- data/bmc-daemon-lib.gemspec +1 -1
- data/lib/bmc-daemon-lib/mq_consumer.rb +30 -7
- data/lib/bmc-daemon-lib/mq_endpoint.rb +7 -30
- metadata +2 -4
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d35dc7459d4725ea9f2234844440abe29cad87b
|
4
|
+
data.tar.gz: 3dc02b5f47fab8ecbc0271ca35c083d0274c2412
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780b1db309c13e2f35d26748f82159addb7184a1bfcb359f9bb5f8e0d14baee7184ca8b8b8e76a70d4003671e6d2238fb286af53d14fb5a901061599d01ad130
|
7
|
+
data.tar.gz: 8542935eeca326c272a8b5bcf067a779842a1d6f0e30af62601282cf75d17bc34654b250e80886743649dff55d186ee41981ffabd420a30e9caefeb9cdefeb2d
|
data/.gitignore
CHANGED
data/bmc-daemon-lib.gemspec
CHANGED
@@ -9,7 +9,14 @@ module BmcDaemonLib
|
|
9
9
|
include LoggerHelper
|
10
10
|
|
11
11
|
def subscribe_to_queue name, context = nil
|
12
|
-
|
12
|
+
log_debug "subscribe_to_queue [#{name}]"
|
13
|
+
|
14
|
+
# Ensure a channel has been successfully opened first
|
15
|
+
unless @channel
|
16
|
+
error = "subscribe_to_queue: no active channel (call subscribe_to_queue beforehand)"
|
17
|
+
log_error error
|
18
|
+
raise MqConsumerException, error
|
19
|
+
end
|
13
20
|
|
14
21
|
# Queue for this rule
|
15
22
|
@queue = @channel.queue(name, auto_delete: false, durable: true)
|
@@ -21,18 +28,34 @@ module BmcDaemonLib
|
|
21
28
|
end
|
22
29
|
|
23
30
|
def listen_to topic, rkey
|
24
|
-
# puts "listen_to(#{topic},#{rkey})"
|
25
31
|
log_info "listen_to [#{topic}] [#{rkey}] > [#{@queue.name}]"
|
26
|
-
|
32
|
+
|
33
|
+
# Ensure a queue has been successfully subscribed first
|
34
|
+
unless @queue
|
35
|
+
error = "listen_to: no active queue (call subscribe_to_queue beforehand)"
|
36
|
+
log_error error
|
37
|
+
raise MqConsumerException, error
|
38
|
+
end
|
39
|
+
|
40
|
+
# Link or create exchange
|
41
|
+
exchange = @channel.topic(topic, durable: true)
|
42
|
+
|
43
|
+
# puts "listen_to(#{topic},#{rkey})"
|
44
|
+
@queue.bind exchange, routing_key: rkey
|
27
45
|
|
28
46
|
# Handle errors
|
29
|
-
rescue Bunny::NotFound => e
|
30
|
-
|
31
|
-
|
47
|
+
# rescue Bunny::NotFound => e
|
48
|
+
# log_debug "creating missing exchange [#{topic}]"
|
49
|
+
# @channel.topic topic, durable: false, auto_delete: true
|
50
|
+
# retry
|
51
|
+
# # raise MqConsumerTopicNotFound, e.message
|
32
52
|
|
33
53
|
rescue StandardError => e
|
34
|
-
log_error "UNEXPECTED
|
54
|
+
log_error "UNEXPECTED: #{e.inspect}"
|
35
55
|
raise MqConsumerException, e.message
|
56
|
+
|
57
|
+
else
|
58
|
+
# log_debug "bound queue [#{@queue.name}] on topic [#{topic}]"
|
36
59
|
end
|
37
60
|
|
38
61
|
protected
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module BmcDaemonLib
|
2
|
-
class EndpointConnexionContext < StandardError; end
|
3
|
-
class EndpointConnectionError < StandardError; end
|
4
|
-
class EndpointSubscribeContext < StandardError; end
|
5
|
-
class EndpointSubscribeError < StandardError; end
|
6
2
|
|
7
3
|
class MqEndpoint
|
8
4
|
include LoggerHelper
|
5
|
+
attr_accessor :logger
|
6
|
+
|
7
|
+
def initialize channel, *args
|
8
|
+
# Init
|
9
|
+
@channel = channel
|
10
|
+
log_info "MqEndpoint on channel [#{@channel.id}]"
|
11
|
+
end
|
9
12
|
|
10
13
|
protected
|
11
14
|
|
@@ -38,31 +41,5 @@ module BmcDaemonLib
|
|
38
41
|
return "#{truncated} #{units[index]}#{unit}"
|
39
42
|
end
|
40
43
|
|
41
|
-
# Start connexion to RabbitMQ
|
42
|
-
def connect_to busconf
|
43
|
-
fail BmcDaemonLib::EndpointConnexionContext, "connect_to/busconf" unless busconf
|
44
|
-
log_info "connecting to bus", {
|
45
|
-
broker: busconf,
|
46
|
-
recover: AMQP_RECOVERY_INTERVAL,
|
47
|
-
heartbeat: AMQP_HEARTBEAT_INTERVAL,
|
48
|
-
prefetch: AMQP_PREFETCH
|
49
|
-
}
|
50
|
-
conn = Bunny.new busconf.to_s,
|
51
|
-
logger: @logger,
|
52
|
-
# heartbeat: :server,
|
53
|
-
automatically_recover: true,
|
54
|
-
network_recovery_interval: AMQP_RECOVERY_INTERVAL,
|
55
|
-
heartbeat_interval: AMQP_HEARTBEAT_INTERVAL,
|
56
|
-
read_write_timeout: AMQP_HEARTBEAT_INTERVAL*2
|
57
|
-
conn.start
|
58
|
-
|
59
|
-
rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::AuthenticationFailureError, AMQ::Protocol::EmptyResponseError => e
|
60
|
-
fail BmcDaemonLib::EndpointConnectionError, "error connecting (#{e.class})"
|
61
|
-
rescue StandardError => e
|
62
|
-
fail BmcDaemonLib::EndpointConnectionError, "unknow (#{e.inspect})"
|
63
|
-
else
|
64
|
-
return conn
|
65
|
-
end
|
66
|
-
|
67
44
|
end
|
68
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmc-daemon-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,9 +101,7 @@ extensions: []
|
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
103
|
- ".gitignore"
|
104
|
-
- ".ruby-version"
|
105
104
|
- Gemfile
|
106
|
-
- Gemfile.lock
|
107
105
|
- LICENSE
|
108
106
|
- README.md
|
109
107
|
- Rakefile
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.2
|
data/Gemfile.lock
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bmc-daemon-lib (0.9.2)
|
5
|
-
chamber
|
6
|
-
hashie (~> 3.4.6)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
ast (2.3.0)
|
12
|
-
chamber (2.10.1)
|
13
|
-
hashie (~> 3.3)
|
14
|
-
thor (~> 0.19.1)
|
15
|
-
diff-lcs (1.3)
|
16
|
-
hashie (3.4.6)
|
17
|
-
parser (2.4.0.0)
|
18
|
-
ast (~> 2.2)
|
19
|
-
powerpack (0.1.1)
|
20
|
-
rainbow (2.2.1)
|
21
|
-
rake (12.0.0)
|
22
|
-
rspec (3.5.0)
|
23
|
-
rspec-core (~> 3.5.0)
|
24
|
-
rspec-expectations (~> 3.5.0)
|
25
|
-
rspec-mocks (~> 3.5.0)
|
26
|
-
rspec-core (3.5.4)
|
27
|
-
rspec-support (~> 3.5.0)
|
28
|
-
rspec-expectations (3.5.0)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.5.0)
|
31
|
-
rspec-mocks (3.5.0)
|
32
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.5.0)
|
34
|
-
rspec-support (3.5.0)
|
35
|
-
rubocop (0.47.1)
|
36
|
-
parser (>= 2.3.3.1, < 3.0)
|
37
|
-
powerpack (~> 0.1)
|
38
|
-
rainbow (>= 1.99.1, < 3.0)
|
39
|
-
ruby-progressbar (~> 1.7)
|
40
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
41
|
-
ruby-progressbar (1.8.1)
|
42
|
-
thor (0.19.4)
|
43
|
-
unicode-display_width (1.1.3)
|
44
|
-
|
45
|
-
PLATFORMS
|
46
|
-
ruby
|
47
|
-
|
48
|
-
DEPENDENCIES
|
49
|
-
bmc-daemon-lib!
|
50
|
-
bundler
|
51
|
-
rake
|
52
|
-
rspec
|
53
|
-
rubocop
|
54
|
-
|
55
|
-
BUNDLED WITH
|
56
|
-
1.13.7
|