beetle 3.4.2 → 3.4.3

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
  SHA256:
3
- metadata.gz: '08db25367467939ff6a625b0caf2b940832b398c7988189ac2a0e91d5244a78b'
4
- data.tar.gz: d9ffc4a722b0d86db98e81e0f9080b76e2fbd01537cbb4a6839b00665e778f19
3
+ metadata.gz: 64be33377e4235036fac944de3c020f03fc53e426a1969b729ca0db016351cae
4
+ data.tar.gz: 7fde625b27bce1814ba5840b92898b7cb365f1d04b743584b59e15e6bb9d7da7
5
5
  SHA512:
6
- metadata.gz: c7f986880a871a59a74ee9e3fc63b9b384097713eedc9f106c7b799cd6b8762714d05d181665ac5aadea0675fd10f30acfbaec8fcdf921a31721c609220b95ad
7
- data.tar.gz: 3beb91290f71cf8191f9abe0a116732e0e880a3e0e57d2c774c2c417bde4fb697b7980e2d2f6af0bdfcd601b124c7c4286a796fada014771be3bb8b049130d12
6
+ metadata.gz: 990d179e32cad50f9d51ec3f3bf8e4e3d518b8f1925995277917ae5553dfd3fd72dd510558a3f2f5ddbc815b57f5a8719f3854b18b2680a620f76dda1bb411b5
7
+ data.tar.gz: 42e77ac9b05035ec28891cdf43eb8ba0706e835a52d4c1906843a7d9f1cf8a9a211c332c2d031c5b044b2f4cebbf40ca94a8dd20eda99abc0af0c8cf9ce9ce29
@@ -1,5 +1,8 @@
1
1
  = Release Notes
2
2
 
3
+ == Version 3.4.3
4
+ * optimize declaration of queues with many bindings
5
+
3
6
  == Version 3.4.2
4
7
  * Updated amq-protocol gem to version 2.3.2.
5
8
  * Fixed a rare race condition on message handler timeouts.
@@ -67,23 +67,25 @@ module Beetle
67
67
  logger.debug("Beetle: binding queue #{name} with internal name #{opts[:amqp_name]} on server #{@server}")
68
68
  queue_name = opts[:amqp_name]
69
69
  creation_options = opts.slice(*QUEUE_CREATION_KEYS)
70
- the_queue = nil
70
+
71
+ the_queue = declare_queue!(queue_name, creation_options)
71
72
  @client.bindings[name].each do |binding_options|
72
73
  exchange_name = binding_options[:exchange]
73
74
  binding_options = binding_options.slice(*QUEUE_BINDING_KEYS)
74
- the_queue = bind_queue!(queue_name, creation_options, exchange_name, binding_options)
75
+ logger.debug("Beetle: binding queue #{queue_name} to #{exchange_name} with opts: #{binding_options.inspect}")
76
+ bind_queue!(the_queue, exchange_name, binding_options)
75
77
  end
76
78
  the_queue
77
79
  end
78
80
  end
79
81
 
80
- def bind_dead_letter_queue!(channel, target_queue, creation_keys = {})
82
+ def bind_dead_letter_queue!(channel, target_queue, creation_options = {})
81
83
  policy_options = @client.queues[target_queue].slice(:dead_lettering, :lazy, :dead_lettering_msg_ttl)
82
84
  policy_options[:message_ttl] = policy_options.delete(:dead_lettering_msg_ttl)
83
85
  dead_letter_queue_name = "#{target_queue}_dead_letter"
84
86
  if policy_options[:dead_lettering]
85
- logger.debug("Beetle: creating dead letter queue #{dead_letter_queue_name} with opts: #{creation_keys.inspect}")
86
- channel.queue(dead_letter_queue_name, creation_keys)
87
+ logger.debug("Beetle: creating dead letter queue #{dead_letter_queue_name} with opts: #{creation_options.inspect}")
88
+ channel.queue(dead_letter_queue_name, creation_options)
87
89
  end
88
90
  return {
89
91
  :queue_name => target_queue,
@@ -93,7 +95,7 @@ module Beetle
93
95
  }.merge(policy_options)
94
96
  end
95
97
 
96
- # called by <tt>bind_queue!</tt>
98
+ # called by <tt>declare_queue!</tt>
97
99
  def publish_policy_options(options)
98
100
  # avoid endless recursion
99
101
  return if options[:queue_name] == @client.config.beetle_policy_updates_queue_name
@@ -247,17 +247,19 @@ module Beetle
247
247
  @exchanges_with_bound_queues[exchange_name] = true
248
248
  end
249
249
 
250
- # TODO: Refactor, fetch the keys and stuff itself
251
- def bind_queue!(queue_name, creation_keys, exchange_name, binding_keys)
252
- logger.debug("Beetle: creating queue with opts: #{creation_keys.inspect}")
253
- queue = bunny.queue(queue_name, creation_keys)
254
- logger.debug("Beetle: binding queue #{queue_name} to #{exchange_name} with opts: #{binding_keys.inspect}")
255
- queue.bind(exchange(exchange_name), binding_keys)
256
- policy_options = bind_dead_letter_queue!(bunny, queue_name, creation_keys)
250
+ def declare_queue!(queue_name, creation_options)
251
+ logger.debug("Beetle: creating queue with opts: #{creation_options.inspect}")
252
+ queue = bunny.queue(queue_name, creation_options)
253
+
254
+ policy_options = bind_dead_letter_queue!(bunny, queue_name, creation_options)
257
255
  publish_policy_options(policy_options)
258
256
  queue
259
257
  end
260
258
 
259
+ def bind_queue!(queue, exchange_name, binding_options)
260
+ queue.bind(exchange(exchange_name), binding_options)
261
+ end
262
+
261
263
  def stop!(exception=nil)
262
264
  return unless bunny?
263
265
  timeout = @client.config.publishing_timeout + @client.config.publisher_connect_timeout + 1
@@ -214,18 +214,20 @@ module Beetle
214
214
  channel.__send__(opts[:type], name, opts.slice(*EXCHANGE_CREATION_KEYS))
215
215
  end
216
216
 
217
- def bind_queue!(queue_name, creation_keys, exchange_name, binding_keys)
218
- queue = channel.queue(queue_name, creation_keys)
217
+ def declare_queue!(queue_name, creation_options)
218
+ queue = channel.queue(queue_name, creation_options)
219
219
  unless tracing?
220
220
  # we don't want to create dead-letter queues for tracing
221
- policy_options = bind_dead_letter_queue!(channel, queue_name, creation_keys)
221
+ policy_options = bind_dead_letter_queue!(channel, queue_name, creation_options)
222
222
  publish_policy_options(policy_options)
223
223
  end
224
- exchange = exchange(exchange_name)
225
- queue.bind(exchange, binding_keys)
226
224
  queue
227
225
  end
228
226
 
227
+ def bind_queue!(queue, exchange_name, binding_options)
228
+ queue.bind(exchange(exchange_name), binding_options)
229
+ end
230
+
229
231
  def connection_settings
230
232
  {
231
233
  :host => current_host, :port => current_port, :logging => false,
@@ -1,3 +1,3 @@
1
1
  module Beetle
2
- VERSION = "3.4.2"
2
+ VERSION = "3.4.3"
3
3
  end
@@ -304,7 +304,9 @@ module Beetle
304
304
  @client.register_queue('test_queue_1', :exchange => 'test_exchange')
305
305
  @client.register_queue('test_queue_2', :exchange => 'test_exchange')
306
306
  @client.register_queue('test_queue_3', :exchange => 'test_exchange_2')
307
- @pub.expects(:bind_queue!).returns(1).times(3)
307
+ queue = mock("queue")
308
+ queue.expects(:bind).times(3)
309
+ @pub.expects(:declare_queue!).returns(queue).times(3)
308
310
  @pub.send(:bind_queues_for_exchange, 'test_exchange')
309
311
  @pub.send(:bind_queues_for_exchange, 'test_exchange_2')
310
312
  end
@@ -312,8 +314,19 @@ module Beetle
312
314
  test "should not rebind the defined queues for the used exchanges if they already have been bound" do
313
315
  @client.register_queue('test_queue_1', :exchange => 'test_exchange')
314
316
  @client.register_queue('test_queue_2', :exchange => 'test_exchange')
315
- @pub.expects(:bind_queue!).twice
317
+ queue = mock("queue")
318
+ queue.expects(:bind).twice
319
+ @pub.expects(:declare_queue!).returns(queue).twice
320
+ @pub.send(:bind_queues_for_exchange, 'test_exchange')
316
321
  @pub.send(:bind_queues_for_exchange, 'test_exchange')
322
+ end
323
+
324
+ test "should declare queues only once even with many bindings" do
325
+ @client.register_queue('test_queue', :exchange => 'test_exchange')
326
+ @client.register_binding('test_queue', :exchange => 'test_exchange', :key => 'sir-message-a-lot')
327
+ queue = mock("queue")
328
+ queue.expects(:bind).twice
329
+ @pub.expects(:declare_queue!).returns(queue).once
317
330
  @pub.send(:bind_queues_for_exchange, 'test_exchange')
318
331
  end
319
332
 
@@ -168,6 +168,17 @@ module Beetle
168
168
  @sub.send(:bind_queues, %W(x y))
169
169
  end
170
170
 
171
+ test "binding queues with many bindings should create it only once" do
172
+ @client.register_queue(:x, :exchange => 'test_exchange')
173
+ @client.register_binding(:x, :exchange => 'test_exchange', :key => 'sir-message-a-lot')
174
+ @client.register_handler(%w(x)){}
175
+ @sub.stubs(:exchange)
176
+ queue = mock("queue")
177
+ queue.expects(:bind).twice
178
+ @sub.expects(:declare_queue!).returns(queue).once
179
+ @sub.send(:bind_queues, %W(x))
180
+ end
181
+
171
182
  test "subscribing to queues should subscribe on all queues" do
172
183
  @client.register_queue(:x)
173
184
  @client.register_queue(:y)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-12-01 00:00:00.000000000 Z
15
+ date: 2021-01-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bunny