bunny 0.10.4 → 0.10.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9c9bf09dd970ef5209cce72c05a7d73f82f4750
4
- data.tar.gz: d658fe0aea0c6f3461b2f4d1c54db3b7d8c0f9a6
3
+ metadata.gz: 30cd6500ecfd75b3739c29654e916438ec46851e
4
+ data.tar.gz: 2099cdb7829fcbd14dfe105b924b227ec764b052
5
5
  SHA512:
6
- metadata.gz: 220ac2fd8093683bfdb6b6c614b8198a47a996295804bd677d3aebfa6001eb1e5dfd7ad63b359e98050fb285f680c0ba5867b9a7f88d2437487db81cc25e84c1
7
- data.tar.gz: a59a8fce37f7807548223b15041d349f5ec8522342427277cebb2de729a0927fde4fb660e5b4ea869b3abd395610e5bc9d3844e126f4d8d7476ce260f0cbae1a
6
+ metadata.gz: 4eef9cc1148e341756184bb7685f84dc34d55ad3db86b030277360474e8cb13cdbbdf6f1323852e56f4deac0c8fc17ac072c295f610678d5e5aa2325ec50a81b
7
+ data.tar.gz: 7d69d18fc1d4eccaec10fe33423490b9b9bae51abc031170e658b3070706c6e29cc8c80d14d0ac444b28ab6faaf1a5ee362c73f78dc7b45c13f8358b3c25ccf6
@@ -1,3 +1,16 @@
1
+ ## Changes between Bunny 0.10.4 and 0.10.5
2
+
3
+ ### Bunny::Session.parse_uri
4
+
5
+ `Bunny::Session.parse_uri` is a new method that parses
6
+ connection URIs into hashes that `Bunny::Session#initialize`
7
+ accepts.
8
+
9
+ ``` ruby
10
+ Bunny::Session.parse_uri("amqp://user:pwd@broker.eng.megacorp.local/myapp_qa")
11
+ ```
12
+
13
+
1
14
  ## Changes between Bunny 0.10.3 and 0.10.4
2
15
 
3
16
  ### Default Paths for TLS/SSL CA's on All OS'es
@@ -9,6 +9,7 @@ require "amq/protocol/extensions"
9
9
  require "bunny/framing"
10
10
  require "bunny/exceptions"
11
11
  require "bunny/socket"
12
+ require "bunny/timeout"
12
13
 
13
14
  begin
14
15
  require "openssl"
@@ -33,20 +34,6 @@ module Bunny
33
34
  # AMQP protocol version Bunny implements
34
35
  PROTOCOL_VERSION = AMQ::Protocol::PROTOCOL_VERSION
35
36
 
36
- # unifies Ruby standard library's Timeout (which is not accurate on
37
- # Ruby 1.8 and has other issues) and SystemTimer (the gem)
38
- Timer = if RUBY_VERSION < "1.9"
39
- begin
40
- require "bunny/system_timer"
41
- Bunny::SystemTimer
42
- rescue LoadError
43
- Timeout
44
- end
45
- else
46
- Timeout
47
- end
48
-
49
-
50
37
  #
51
38
  # API
52
39
  #
@@ -602,7 +602,7 @@ module Bunny
602
602
 
603
603
  @connection.send_frame(AMQ::Protocol::Basic::Qos.encode(@id, 0, prefetch_count, global))
604
604
 
605
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
605
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
606
606
  @last_basic_qos_ok = wait_on_continuations
607
607
  end
608
608
  raise_if_continuation_resulted_in_a_channel_error!
@@ -621,7 +621,7 @@ module Bunny
621
621
  raise_if_no_longer_open!
622
622
 
623
623
  @connection.send_frame(AMQ::Protocol::Basic::Recover.encode(@id, requeue))
624
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
624
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
625
625
  @last_basic_recover_ok = wait_on_continuations
626
626
  end
627
627
  raise_if_continuation_resulted_in_a_channel_error!
@@ -823,7 +823,7 @@ module Bunny
823
823
  arguments))
824
824
 
825
825
  begin
826
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
826
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
827
827
  @last_basic_consume_ok = wait_on_continuations
828
828
  end
829
829
  rescue Exception => e
@@ -873,7 +873,7 @@ module Bunny
873
873
  consumer.arguments))
874
874
 
875
875
  begin
876
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
876
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
877
877
  @last_basic_consume_ok = wait_on_continuations
878
878
  end
879
879
  rescue Exception => e
@@ -908,7 +908,7 @@ module Bunny
908
908
  def basic_cancel(consumer_tag)
909
909
  @connection.send_frame(AMQ::Protocol::Basic::Cancel.encode(@id, consumer_tag, false))
910
910
 
911
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
911
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
912
912
  @last_basic_cancel_ok = wait_on_continuations
913
913
  end
914
914
 
@@ -982,7 +982,7 @@ module Bunny
982
982
  opts[:if_unused],
983
983
  opts[:if_empty],
984
984
  false))
985
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
985
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
986
986
  @last_queue_delete_ok = wait_on_continuations
987
987
  end
988
988
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1002,7 +1002,7 @@ module Bunny
1002
1002
 
1003
1003
  @connection.send_frame(AMQ::Protocol::Queue::Purge.encode(@id, name, false))
1004
1004
 
1005
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1005
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1006
1006
  @last_queue_purge_ok = wait_on_continuations
1007
1007
  end
1008
1008
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1038,7 +1038,7 @@ module Bunny
1038
1038
  opts[:routing_key],
1039
1039
  false,
1040
1040
  opts[:arguments]))
1041
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1041
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1042
1042
  @last_queue_bind_ok = wait_on_continuations
1043
1043
  end
1044
1044
 
@@ -1073,7 +1073,7 @@ module Bunny
1073
1073
  exchange_name,
1074
1074
  opts[:routing_key],
1075
1075
  opts[:arguments]))
1076
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1076
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1077
1077
  @last_queue_unbind_ok = wait_on_continuations
1078
1078
  end
1079
1079
 
@@ -1112,7 +1112,7 @@ module Bunny
1112
1112
  false,
1113
1113
  false,
1114
1114
  opts[:arguments]))
1115
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1115
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1116
1116
  @last_exchange_declare_ok = wait_on_continuations
1117
1117
  end
1118
1118
 
@@ -1137,7 +1137,7 @@ module Bunny
1137
1137
  name,
1138
1138
  opts[:if_unused],
1139
1139
  false))
1140
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1140
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1141
1141
  @last_exchange_delete_ok = wait_on_continuations
1142
1142
  end
1143
1143
 
@@ -1181,7 +1181,7 @@ module Bunny
1181
1181
  opts[:routing_key],
1182
1182
  false,
1183
1183
  opts[:arguments]))
1184
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1184
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1185
1185
  @last_exchange_bind_ok = wait_on_continuations
1186
1186
  end
1187
1187
 
@@ -1225,7 +1225,7 @@ module Bunny
1225
1225
  opts[:routing_key],
1226
1226
  false,
1227
1227
  opts[:arguments]))
1228
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1228
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1229
1229
  @last_exchange_unbind_ok = wait_on_continuations
1230
1230
  end
1231
1231
 
@@ -1253,7 +1253,7 @@ module Bunny
1253
1253
  raise_if_no_longer_open!
1254
1254
 
1255
1255
  @connection.send_frame(AMQ::Protocol::Channel::Flow.encode(@id, active))
1256
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1256
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1257
1257
  @last_channel_flow_ok = wait_on_continuations
1258
1258
  end
1259
1259
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1274,7 +1274,7 @@ module Bunny
1274
1274
  raise_if_no_longer_open!
1275
1275
 
1276
1276
  @connection.send_frame(AMQ::Protocol::Tx::Select.encode(@id))
1277
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1277
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1278
1278
  @last_tx_select_ok = wait_on_continuations
1279
1279
  end
1280
1280
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1289,7 +1289,7 @@ module Bunny
1289
1289
  raise_if_no_longer_open!
1290
1290
 
1291
1291
  @connection.send_frame(AMQ::Protocol::Tx::Commit.encode(@id))
1292
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1292
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1293
1293
  @last_tx_commit_ok = wait_on_continuations
1294
1294
  end
1295
1295
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1304,7 +1304,7 @@ module Bunny
1304
1304
  raise_if_no_longer_open!
1305
1305
 
1306
1306
  @connection.send_frame(AMQ::Protocol::Tx::Rollback.encode(@id))
1307
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1307
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1308
1308
  @last_tx_rollback_ok = wait_on_continuations
1309
1309
  end
1310
1310
  raise_if_continuation_resulted_in_a_channel_error!
@@ -1344,7 +1344,7 @@ module Bunny
1344
1344
  @confirms_callback = callback
1345
1345
 
1346
1346
  @connection.send_frame(AMQ::Protocol::Confirm::Select.encode(@id, false))
1347
- Bunny::Timer.timeout(read_write_timeout, ClientTimeout) do
1347
+ Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
1348
1348
  @last_confirm_select_ok = wait_on_continuations
1349
1349
  end
1350
1350
  raise_if_continuation_resulted_in_a_channel_error!
@@ -21,7 +21,7 @@ module Bunny
21
21
 
22
22
  def poll(timeout_in_ms = nil)
23
23
  if timeout_in_ms
24
- Bunny::Timer.timeout(timeout_in_ms / 1000, Timeout::Error) do
24
+ Bunny::Timeout.timeout(timeout_in_ms / 1000, Timeout::Error) do
25
25
  @q.pop
26
26
  end
27
27
  else
@@ -97,18 +97,23 @@ module Bunny
97
97
  # @option connection_string_or_opts [String] :password ("guest") Password
98
98
  # @option connection_string_or_opts [String] :vhost ("/") Virtual host to use
99
99
  # @option connection_string_or_opts [Integer] :heartbeat (600) Heartbeat interval. 0 means no heartbeat.
100
+ # @option connection_string_or_opts [Boolean] :tls (false) Should TLS/SSL be used?
101
+ # @option connection_string_or_opts [String] :tls_cert (nil) Path to client TLS/SSL certificate file (.pem)
102
+ # @option connection_string_or_opts [String] :tls_key (nil) Path to client TLS/SSL private key file (.pem)
103
+ # @option connection_string_or_opts [Array<String>] :tls_ca_certificates Array of paths to TLS/SSL CA files (.pem), by default detected from OpenSSL configuration
100
104
  #
101
105
  # @option optz [String] :auth_mechanism ("PLAIN") Authentication mechanism, PLAIN or EXTERNAL
102
106
  # @option optz [String] :locale ("PLAIN") Locale RabbitMQ should use
103
107
  #
104
108
  # @see http://rubybunny.info/articles/connecting.html Connecting to RabbitMQ guide
109
+ # @see http://rubybunny.info/articles/tls.html TLS/SSL guide
105
110
  # @api public
106
111
  def initialize(connection_string_or_opts = Hash.new, optz = Hash.new)
107
112
  opts = case (ENV["RABBITMQ_URL"] || connection_string_or_opts)
108
113
  when nil then
109
114
  Hash.new
110
115
  when String then
111
- AMQ::Settings.parse_amqp_url(connection_string_or_opts)
116
+ self.class.parse_uri(connection_string_or_opts)
112
117
  when Hash then
113
118
  connection_string_or_opts
114
119
  end.merge(optz)
@@ -193,6 +198,8 @@ module Bunny
193
198
  # @private
194
199
  attr_reader :mutex_impl
195
200
 
201
+ # Provides a way to fine tune the socket used by connection.
202
+ # Accepts a block that the socket will be yielded to.
196
203
  def configure_socket(&block)
197
204
  raise ArgumentError, "No block provided!" if block.nil?
198
205
 
@@ -265,7 +272,7 @@ module Bunny
265
272
  if @transport.open?
266
273
  close_all_channels
267
274
 
268
- Bunny::Timer.timeout(@transport.disconnect_timeout, ClientTimeout) do
275
+ Bunny::Timeout.timeout(@transport.disconnect_timeout, ClientTimeout) do
269
276
  self.close_connection(true)
270
277
  end
271
278
 
@@ -342,6 +349,41 @@ module Bunny
342
349
  @default_channel.exchange(*args)
343
350
  end
344
351
 
352
+ # Defines a callback that will be executed when RabbitMQ blocks the connection
353
+ # because it is running low on memory or disk space (as configured via config file
354
+ # and/or rabbitmqctl).
355
+ #
356
+ # @yield [AMQ::Protocol::Connection::Blocked] connection.blocked method which provides a reason for blocking
357
+ #
358
+ # @api public
359
+ def on_blocked(&block)
360
+ @block_callback = block
361
+ end
362
+
363
+ # Defines a callback that will be executed when RabbitMQ unblocks the connection
364
+ # that was previously blocked, e.g. because the memory or disk space alarm has cleared.
365
+ #
366
+ # @see #on_blocked
367
+ # @api public
368
+ def on_unblocked(&block)
369
+ @unblock_callback = block
370
+ end
371
+
372
+ # @return [Boolean] true if the connection is currently blocked by RabbitMQ because it's running low on
373
+ # RAM, disk space, or other resource; false otherwise
374
+ # @see #on_blocked
375
+ # @see #on_unblocked
376
+ def blocked?
377
+ @blocked
378
+ end
379
+
380
+ # Parses an amqp[s] URI into a hash that {Bunny::Session#initialize} accepts.
381
+ #
382
+ # @param [String] uri amqp or amqps URI to parse
383
+ # @return [Hash] Parsed URI as a hash
384
+ def self.parse_uri(uri)
385
+ AMQ::Settings.parse_amqp_url(uri)
386
+ end
345
387
 
346
388
  #
347
389
  # Implementation
@@ -376,7 +418,7 @@ module Bunny
376
418
  # @private
377
419
  def close_all_channels
378
420
  @channels.reject {|n, ch| n == 0 || !ch.open? }.each do |_, ch|
379
- Bunny::Timer.timeout(@transport.disconnect_timeout, ClientTimeout) { ch.close }
421
+ Bunny::Timeout.timeout(@transport.disconnect_timeout, ClientTimeout) { ch.close }
380
422
  end
381
423
  end
382
424
 
@@ -635,7 +677,7 @@ module Bunny
635
677
  # a native method that cannot be (easily) interrupted.
636
678
  # So we use this ugly hack or else our test suite takes forever
637
679
  # to run on JRuby (a new connection is opened/closed per example). MK.
638
- if RUBY_ENGINE == "jruby"
680
+ if defined?(JRUBY_VERSION)
639
681
  sleep 0.075
640
682
  else
641
683
  @reader_loop.join
@@ -0,0 +1,18 @@
1
+ module Bunny
2
+ # Unifies Ruby standard library's Timeout (which is not accurate on
3
+ # Ruby 1.8) and SystemTimer (the gem)
4
+ Timeout = if RUBY_VERSION < "1.9"
5
+ begin
6
+ require "bunny/system_timer"
7
+ Bunny::SystemTimer
8
+ rescue LoadError
9
+ Timeout
10
+ end
11
+ else
12
+ Timeout
13
+ end
14
+
15
+ # Backwards compatibility
16
+ # @private
17
+ Timer = Timeout
18
+ end
@@ -112,7 +112,7 @@ module Bunny
112
112
  def write(data)
113
113
  begin
114
114
  if @read_write_timeout
115
- Bunny::Timer.timeout(@read_write_timeout, Bunny::ClientTimeout) do
115
+ Bunny::Timeout.timeout(@read_write_timeout, Bunny::ClientTimeout) do
116
116
  if open?
117
117
  @writes_mutex.synchronize { @socket.write(data) }
118
118
  @socket.flush
@@ -250,7 +250,7 @@ module Bunny
250
250
 
251
251
  def initialize_socket
252
252
  begin
253
- @socket = Bunny::Timer.timeout(@connect_timeout, ConnectionTimeout) do
253
+ @socket = Bunny::Timeout.timeout(@connect_timeout, ConnectionTimeout) do
254
254
  Bunny::Socket.open(@host, @port,
255
255
  :keepalive => @opts[:keepalive],
256
256
  :socket_timeout => @connect_timeout)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bunny
4
4
  # @return [String] Version of the library
5
- VERSION = "0.10.4"
5
+ VERSION = "0.10.5"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-08-24 00:00:00.000000000 Z
15
+ date: 2013-08-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: amq-protocol
@@ -123,6 +123,7 @@ files:
123
123
  - lib/bunny/ssl_socket.rb
124
124
  - lib/bunny/system_timer.rb
125
125
  - lib/bunny/test_kit.rb
126
+ - lib/bunny/timeout.rb
126
127
  - lib/bunny/transport.rb
127
128
  - lib/bunny/version.rb
128
129
  - lib/bunny/versioned_delivery_tag.rb