sensu-transport 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/sensu/transport/rabbitmq.rb +48 -35
- data/sensu-transport.gemspec +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 453c7441cdd99a8ac5db0aa1a73bf2122ecd628d
|
4
|
+
data.tar.gz: 9fa00ddc17d02956b06983109ab190e5290a4fe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e50c0f00787c8764fc01e0ef2afed3f15cc7fbf18c1ca16919c82f4a3461f7e56e4eb697ab3d2bc94536e2b344ce42b3f3d50a0f9068a7b95a0d711a8bd65ff
|
7
|
+
data.tar.gz: 088f59bf49ce59e4b8f5ce3adacb34ff31828d15b8f23b9084c2e0b6b849af2c707f719c75a7496f338b749e7d191836e0eb1ecd0cfc7e5cd733f80187ababca
|
data/.gitignore
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
gem "amqp", "1.
|
1
|
+
gem "amqp", "1.5.0"
|
2
2
|
|
3
3
|
require "amqp"
|
4
4
|
|
@@ -7,40 +7,28 @@ require File.join(File.dirname(__FILE__), "base")
|
|
7
7
|
module Sensu
|
8
8
|
module Transport
|
9
9
|
class RabbitMQ < Base
|
10
|
-
def initialize
|
11
|
-
super
|
12
|
-
@queues = {}
|
13
|
-
end
|
14
|
-
|
15
10
|
def connect(options={})
|
11
|
+
reset
|
12
|
+
set_connection_options(options)
|
16
13
|
create_connection_timeout
|
17
|
-
|
18
|
-
:on_tcp_connection_failure => on_connection_failure,
|
19
|
-
:on_possible_authentication_failure => on_connection_failure
|
20
|
-
})
|
21
|
-
@connection.logger = @logger
|
22
|
-
@connection.on_open do
|
23
|
-
@connection_timeout.cancel
|
24
|
-
end
|
25
|
-
reconnect_callback = Proc.new { reconnect }
|
26
|
-
@connection.on_tcp_connection_loss(&reconnect_callback)
|
27
|
-
@connection.on_skipped_heartbeats(&reconnect_callback)
|
28
|
-
setup_channel(options)
|
14
|
+
connect_with_eligible_options
|
29
15
|
end
|
30
16
|
|
31
17
|
def reconnect
|
32
|
-
unless @
|
33
|
-
@
|
18
|
+
unless @reconnecting
|
19
|
+
@reconnecting = true
|
34
20
|
@before_reconnect.call
|
21
|
+
reset
|
35
22
|
timer = EM::PeriodicTimer.new(5) do
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
unless connected?
|
24
|
+
connect_with_eligible_options do
|
25
|
+
@reconnecting = false
|
26
|
+
@after_reconnect.call
|
27
|
+
end
|
28
|
+
else
|
29
|
+
timer.cancel
|
39
30
|
end
|
40
31
|
end
|
41
|
-
@connection.on_recovery do
|
42
|
-
timer.cancel
|
43
|
-
end
|
44
32
|
end
|
45
33
|
end
|
46
34
|
|
@@ -108,18 +96,46 @@ module Sensu
|
|
108
96
|
|
109
97
|
private
|
110
98
|
|
99
|
+
def reset
|
100
|
+
@queues = {}
|
101
|
+
@connection_timeout.cancel if @connection_timeout
|
102
|
+
@connection.close_connection if @connection
|
103
|
+
end
|
104
|
+
|
105
|
+
def set_connection_options(options)
|
106
|
+
@connection_options = Array(options)
|
107
|
+
end
|
108
|
+
|
111
109
|
def create_connection_timeout
|
112
110
|
@connection_timeout = EM::Timer.new(20) do
|
113
|
-
|
114
|
-
@on_error.call(error)
|
111
|
+
reconnect
|
115
112
|
end
|
116
113
|
end
|
117
114
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
def next_connection_options
|
116
|
+
if @eligible_options.nil? || @eligible_options.empty?
|
117
|
+
@eligible_options = @connection_options.shuffle
|
118
|
+
end
|
119
|
+
@eligible_options.shift
|
120
|
+
end
|
121
|
+
|
122
|
+
def reconnect_callback
|
123
|
+
Proc.new { reconnect }
|
124
|
+
end
|
125
|
+
|
126
|
+
def connect_with_eligible_options(&callback)
|
127
|
+
options = next_connection_options
|
128
|
+
@connection = AMQP.connect(options)
|
129
|
+
@connection.on_tcp_connection_failure(&reconnect_callback)
|
130
|
+
@connection.on_possible_authentication_failure(&reconnect_callback)
|
131
|
+
@connection.logger = @logger
|
132
|
+
@connection.on_open do
|
133
|
+
@connection_timeout.cancel
|
134
|
+
callback.call if callback
|
122
135
|
end
|
136
|
+
@connection.on_tcp_connection_loss(&reconnect_callback)
|
137
|
+
@connection.on_skipped_heartbeats(&reconnect_callback)
|
138
|
+
setup_channel(options)
|
123
139
|
end
|
124
140
|
|
125
141
|
def setup_channel(options={})
|
@@ -134,9 +150,6 @@ module Sensu
|
|
134
150
|
prefetch = options.fetch(:prefetch, 1)
|
135
151
|
end
|
136
152
|
@channel.prefetch(prefetch)
|
137
|
-
@channel.on_recovery do
|
138
|
-
@after_reconnect.call
|
139
|
-
end
|
140
153
|
end
|
141
154
|
end
|
142
155
|
end
|
data/sensu-transport.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "sensu-transport"
|
5
|
-
spec.version = "
|
5
|
+
spec.version = "2.0.0"
|
6
6
|
spec.authors = ["Sean Porter"]
|
7
7
|
spec.email = ["portertech@gmail.com"]
|
8
8
|
spec.summary = "The Sensu transport abstraction library"
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
18
|
spec.add_dependency("sensu-em")
|
19
|
-
spec.add_dependency("amqp", "1.
|
19
|
+
spec.add_dependency("amqp", "1.5.0")
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-em
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.2.
|
144
|
+
rubygems_version: 2.2.2
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: The Sensu transport abstraction library
|
@@ -156,3 +156,4 @@ test_files:
|
|
156
156
|
- spec/helpers.rb
|
157
157
|
- spec/rabbitmq_spec.rb
|
158
158
|
- spec/transport_spec.rb
|
159
|
+
has_rdoc:
|