sensu-transport 7.1.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d0a7bf7281d8344c9f733e8b3f4b35bbaf94f90
4
- data.tar.gz: bdc629bc7e426c81e4858c30040709f52cfd4ff3
3
+ metadata.gz: 63345aafded68e4d6a2343b8226458471e69c9f3
4
+ data.tar.gz: 64945aae01510c75c7c981099c5d9ec3ffed582b
5
5
  SHA512:
6
- metadata.gz: 3e736805fb8440fc3406fd107a80308f5f0fa5e9195a9f2db509b9e6f047793d398628a88d98dc9801fb490068791640f5f732480ff1b49be84ceae518a3992e
7
- data.tar.gz: e0f8829cdf14c594f88e7e16931b01b4e88c232b4cbbfecc111510c1bfeedee3e1fd094ea0a0cc1f0e406bca3e0e16125f1a780dbeabc104dceea5e9bd6cddf5
6
+ metadata.gz: c272ca702a01fcd74f58004a666fd52e2f4784b99b3b10db355833d0ed300d826e3b6302189aa5191bfa12b744bc58d815505bc7e57399724c271b1bdf96bd10
7
+ data.tar.gz: df211a9ecb3b7cab4a4da3c72f0610a522ca36d52704b3283b0873ec45b0542de64ce467c80c5bd572160464a22f0532cd8f01822143bb3f93d215ce28976301
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -37,12 +37,18 @@ module Sensu
37
37
  #
38
38
  # @return [TrueClass, FalseClass]
39
39
  def connected?
40
- @connection && @connection.connected?
40
+ [@publisher_connection, @consumer_connection].all? do |connection|
41
+ connection && connection.connected?
42
+ end
41
43
  end
42
44
 
43
45
  # Close the RabbitMQ connection.
44
46
  def close
45
- callback = Proc.new { @connection.close }
47
+ callback = Proc.new do
48
+ [@publisher_connection, @consumer_connection].each do |connection|
49
+ connection && connection.close
50
+ end
51
+ end
46
52
  connected? ? callback.call : EM.next_tick(callback)
47
53
  end
48
54
 
@@ -60,7 +66,7 @@ module Sensu
60
66
  def publish(type, pipe, message, options={})
61
67
  if connected?
62
68
  catch_errors do
63
- @channel.method(type.to_sym).call(pipe, options).publish(message) do
69
+ @publisher_channel.method(type.to_sym).call(pipe, options).publish(message) do
64
70
  info = {}
65
71
  yield(info) if block_given?
66
72
  end
@@ -85,9 +91,9 @@ module Sensu
85
91
  def subscribe(type, pipe, funnel="", options={}, &callback)
86
92
  catch_errors do
87
93
  previously_declared = @queues.has_key?(funnel)
88
- @queues[funnel] ||= @channel.queue!(funnel, :auto_delete => true)
94
+ @queues[funnel] ||= @consumer_channel.queue!(funnel, :auto_delete => true)
89
95
  queue = @queues[funnel]
90
- queue.bind(@channel.method(type.to_sym).call(pipe))
96
+ queue.bind(@consumer_channel.method(type.to_sym).call(pipe))
91
97
  unless previously_declared
92
98
  queue.subscribe(options, &callback)
93
99
  end
@@ -110,7 +116,7 @@ module Sensu
110
116
  end
111
117
  end
112
118
  @queues = {}
113
- @channel.recover if connected?
119
+ @consumer_channel.recover if connected?
114
120
  end
115
121
  super
116
122
  end
@@ -139,7 +145,7 @@ module Sensu
139
145
  def stats(funnel, options={})
140
146
  catch_errors do
141
147
  options = options.merge(:auto_delete => true)
142
- @channel.queue(funnel, options).status do |messages, consumers|
148
+ @consumer_channel.queue(funnel, options).status do |messages, consumers|
143
149
  info = {
144
150
  :messages => messages,
145
151
  :consumers => consumers
@@ -169,7 +175,9 @@ module Sensu
169
175
  def reset
170
176
  @queues = {}
171
177
  @connection_timeout.cancel if @connection_timeout
172
- @connection.close_connection if @connection
178
+ [@publisher_connection, @consumer_connection].each do |connection|
179
+ connection && connection.close_connection
180
+ end
173
181
  end
174
182
 
175
183
  def set_connection_options(options)
@@ -186,7 +194,7 @@ module Sensu
186
194
  if @eligible_options.nil? || @eligible_options.empty?
187
195
  @eligible_options = @connection_options.shuffle
188
196
  end
189
- options = @eligible_options.shift
197
+ options = @eligible_options.shift || {}
190
198
  if options.is_a?(Hash) && options[:host]
191
199
  resolve_host(options[:host]) do |ip_address|
192
200
  if ip_address.nil?
@@ -200,7 +208,17 @@ module Sensu
200
208
  end
201
209
  end
202
210
 
203
- def setup_connection(options={})
211
+ def connection_ready(&callback)
212
+ if connected?
213
+ @connection_timeout.cancel
214
+ succeed
215
+ callback.call if callback
216
+ end
217
+ end
218
+
219
+ # @param options [Hash]
220
+ # @return [Object] RabbitMQ connection.
221
+ def setup_connection(options={}, &callback)
204
222
  reconnect_callback = Proc.new { reconnect }
205
223
  on_possible_auth_failure = Proc.new {
206
224
  @logger.warn("transport connection error", {
@@ -209,34 +227,36 @@ module Sensu
209
227
  })
210
228
  reconnect
211
229
  }
212
- @connection = AMQP.connect(options, {
230
+ connection = AMQP.connect(options, {
213
231
  :on_tcp_connection_failure => reconnect_callback,
214
232
  :on_possible_authentication_failure => on_possible_auth_failure
215
233
  })
216
- @connection.logger = @logger
217
- @connection.on_open do
234
+ connection.logger = @logger
235
+ connection.on_open do
218
236
  @logger.debug("transport connection open")
219
- @connection_timeout.cancel
220
- succeed
221
- yield if block_given?
237
+ connection_ready(&callback)
222
238
  end
223
- @connection.on_tcp_connection_loss do
239
+ connection.on_tcp_connection_loss do
224
240
  @logger.warn("transport connection error", :reason => "tcp connection lost")
225
241
  reconnect
226
242
  end
227
- @connection.on_skipped_heartbeats do
243
+ connection.on_skipped_heartbeats do
228
244
  @logger.warn("transport connection error", :reason => "skipped heartbeats")
229
245
  reconnect
230
246
  end
231
- @connection.on_closed do
247
+ connection.on_closed do
232
248
  @logger.debug("transport connection closed")
233
249
  end
250
+ connection
234
251
  end
235
252
 
236
- def setup_channel(options={})
237
- @channel = AMQP::Channel.new(@connection)
238
- @channel.auto_recovery = true
239
- @channel.on_error do |channel, channel_close|
253
+ # @param options [Hash]
254
+ # @param connection [Object] RabbitMQ connection.
255
+ # @return [Object] RabbitMQ connection channel.
256
+ def setup_channel(options={}, connection)
257
+ channel = AMQP::Channel.new(connection)
258
+ channel.auto_recovery = true
259
+ channel.on_error do |channel, channel_close|
240
260
  error = Error.new("rabbitmq channel error")
241
261
  @on_error.call(error)
242
262
  end
@@ -244,13 +264,16 @@ module Sensu
244
264
  if options.is_a?(Hash)
245
265
  prefetch = options.fetch(:prefetch, 1)
246
266
  end
247
- @channel.prefetch(prefetch)
267
+ channel.prefetch(prefetch)
268
+ channel
248
269
  end
249
270
 
250
271
  def connect_with_eligible_options(&callback)
251
272
  next_connection_options do |options|
252
- setup_connection(options, &callback)
253
- setup_channel(options)
273
+ @publisher_connection = setup_connection(options, &callback)
274
+ @publisher_channel = setup_channel(options, @publisher_connection)
275
+ @consumer_connection = setup_connection(options, &callback)
276
+ @consumer_channel = setup_channel(options, @consumer_connection)
254
277
  end
255
278
  end
256
279
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-transport"
5
- spec.version = "7.1.0"
5
+ spec.version = "8.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com", "engineering@sensu.io"]
8
8
  spec.summary = "The Sensu transport abstraction library"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
@@ -30,7 +30,7 @@ cert_chain:
30
30
  jOeGyhtQa9j4FFmsEJDg59f5v/3hECXsa3Xuml3foaFHzX3Ya/YIyd2YFxvkFKIu
31
31
  GVbe7A3YdxzdkH2Es/Ym9twdxXaIDdXzj8sWhw==
32
32
  -----END CERTIFICATE-----
33
- date: 2018-03-09 00:00:00.000000000 Z
33
+ date: 2018-10-11 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: eventmachine
metadata.gz.sig CHANGED
Binary file