bunny 3.0.0 → 3.2.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/ChangeLog.md +2630 -0
- data/LICENSE +21 -0
- data/README.md +3 -5
- data/lib/bunny/channel.rb +63 -96
- data/lib/bunny/channel_id_allocator.rb +0 -2
- data/lib/bunny/concurrent/atomic_fixnum.rb +0 -2
- data/lib/bunny/concurrent/condition.rb +0 -3
- data/lib/bunny/concurrent/continuation_queue.rb +0 -2
- data/lib/bunny/concurrent/exception_accumulator.rb +0 -2
- data/lib/bunny/concurrent/synchronized_sorted_set.rb +0 -1
- data/lib/bunny/consumer.rb +1 -1
- data/lib/bunny/consumer_work_pool.rb +0 -2
- data/lib/bunny/cruby/socket.rb +5 -16
- data/lib/bunny/cruby/ssl_socket.rb +4 -15
- data/lib/bunny/delivery_info.rb +7 -7
- data/lib/bunny/exchange.rb +8 -8
- data/lib/bunny/framing.rb +1 -2
- data/lib/bunny/get_response.rb +5 -5
- data/lib/bunny/heartbeat_sender.rb +1 -2
- data/lib/bunny/queue.rb +23 -23
- data/lib/bunny/reader_loop.rb +0 -2
- data/lib/bunny/return_info.rb +4 -4
- data/lib/bunny/session.rb +126 -62
- data/lib/bunny/transport.rb +3 -5
- data/lib/bunny/version.rb +1 -2
- metadata +7 -5
data/lib/bunny/queue.rb
CHANGED
|
@@ -159,7 +159,7 @@ module Bunny
|
|
|
159
159
|
def bind(exchange, opts = {})
|
|
160
160
|
@channel.queue_bind(@name, exchange, opts)
|
|
161
161
|
|
|
162
|
-
exchange_name = if exchange.
|
|
162
|
+
exchange_name = if exchange.is_a?(Bunny::Exchange)
|
|
163
163
|
exchange.name
|
|
164
164
|
else
|
|
165
165
|
exchange
|
|
@@ -168,7 +168,7 @@ module Bunny
|
|
|
168
168
|
|
|
169
169
|
# store bindings for automatic recovery. We need to be very careful to
|
|
170
170
|
# not cause an infinite rebinding loop here when we recover. MK.
|
|
171
|
-
binding = { :
|
|
171
|
+
binding = { exchange: exchange_name, routing_key: (opts[:routing_key] || opts[:key]), arguments: opts[:arguments] }
|
|
172
172
|
@bindings.push(binding) unless @bindings.include?(binding)
|
|
173
173
|
|
|
174
174
|
self
|
|
@@ -188,7 +188,7 @@ module Bunny
|
|
|
188
188
|
def unbind(exchange, opts = {})
|
|
189
189
|
@channel.queue_unbind(@name, exchange, opts)
|
|
190
190
|
|
|
191
|
-
exchange_name = if exchange.
|
|
191
|
+
exchange_name = if exchange.is_a?(Bunny::Exchange)
|
|
192
192
|
exchange.name
|
|
193
193
|
else
|
|
194
194
|
exchange
|
|
@@ -214,11 +214,11 @@ module Bunny
|
|
|
214
214
|
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
|
|
215
215
|
# @api public
|
|
216
216
|
def subscribe(opts = {
|
|
217
|
-
:
|
|
218
|
-
:
|
|
219
|
-
:
|
|
220
|
-
:
|
|
221
|
-
:
|
|
217
|
+
consumer_tag: @channel.generate_consumer_tag,
|
|
218
|
+
manual_ack: false,
|
|
219
|
+
exclusive: false,
|
|
220
|
+
block: false,
|
|
221
|
+
on_cancellation: nil
|
|
222
222
|
}, &block)
|
|
223
223
|
|
|
224
224
|
unless opts[:ack].nil?
|
|
@@ -256,7 +256,7 @@ module Bunny
|
|
|
256
256
|
#
|
|
257
257
|
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
|
|
258
258
|
# @api public
|
|
259
|
-
def subscribe_with(consumer, opts = {:
|
|
259
|
+
def subscribe_with(consumer, opts = { block: false })
|
|
260
260
|
@channel.basic_consume_with(consumer)
|
|
261
261
|
|
|
262
262
|
@channel.work_pool.join if opts[:block]
|
|
@@ -281,13 +281,13 @@ module Bunny
|
|
|
281
281
|
# ch = conn.create_channel
|
|
282
282
|
# q = ch.queue("test1")
|
|
283
283
|
# x = ch.default_exchange
|
|
284
|
-
# x.publish("Hello, everybody!", :
|
|
284
|
+
# x.publish("Hello, everybody!", routing_key: 'test1')
|
|
285
285
|
#
|
|
286
286
|
# delivery_info, properties, payload = q.pop
|
|
287
287
|
#
|
|
288
288
|
# puts "This is the message: " + payload + "\n\n"
|
|
289
289
|
# conn.close
|
|
290
|
-
def pop(opts = {:
|
|
290
|
+
def pop(opts = { manual_ack: false }, &block)
|
|
291
291
|
unless opts[:ack].nil?
|
|
292
292
|
warn "[DEPRECATION] `:ack` is deprecated. Please use `:manual_ack` instead."
|
|
293
293
|
opts[:manual_ack] = opts[:ack]
|
|
@@ -323,7 +323,7 @@ module Bunny
|
|
|
323
323
|
# @see Bunny::Channel#default_exchange
|
|
324
324
|
# @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
|
|
325
325
|
def publish(payload, opts = {})
|
|
326
|
-
@channel.default_exchange.publish(payload, opts.merge(:
|
|
326
|
+
@channel.default_exchange.publish(payload, opts.merge(routing_key: @name))
|
|
327
327
|
|
|
328
328
|
self
|
|
329
329
|
end
|
|
@@ -357,9 +357,9 @@ module Bunny
|
|
|
357
357
|
# @see #message_count
|
|
358
358
|
# @see #consumer_count
|
|
359
359
|
def status
|
|
360
|
-
queue_declare_ok = @channel.queue_declare(@name, @options.merge(:
|
|
361
|
-
{:
|
|
362
|
-
:
|
|
360
|
+
queue_declare_ok = @channel.queue_declare(@name, @options.merge(passive: true))
|
|
361
|
+
{ message_count: queue_declare_ok.message_count,
|
|
362
|
+
consumer_count: queue_declare_ok.consumer_count }
|
|
363
363
|
end
|
|
364
364
|
|
|
365
365
|
# @return [Integer] How many messages the queue has ready (e.g. not delivered but not unacknowledged)
|
|
@@ -378,8 +378,8 @@ module Bunny
|
|
|
378
378
|
# be extra defensive
|
|
379
379
|
args = args0 || {}
|
|
380
380
|
q_type = args["x-queue-type"] || args[:"x-queue-type"]
|
|
381
|
-
|
|
382
|
-
"unsupported queue type #{q_type.inspect}, supported ones: #{Types::KNOWN.join(', ')}"
|
|
381
|
+
raise ArgumentError,
|
|
382
|
+
"unsupported queue type #{q_type.inspect}, supported ones: #{Types::KNOWN.join(', ')}" if (q_type and !Types.known?(q_type))
|
|
383
383
|
end
|
|
384
384
|
|
|
385
385
|
#
|
|
@@ -397,15 +397,15 @@ module Bunny
|
|
|
397
397
|
# @private
|
|
398
398
|
def self.add_default_options(name, opts)
|
|
399
399
|
# :nowait is always false for Bunny
|
|
400
|
-
h = { :
|
|
400
|
+
h = { queue: name, nowait: false }.merge(opts)
|
|
401
401
|
|
|
402
402
|
if name.empty?
|
|
403
403
|
{
|
|
404
|
-
:
|
|
405
|
-
:
|
|
406
|
-
:
|
|
407
|
-
:
|
|
408
|
-
:
|
|
404
|
+
passive: false,
|
|
405
|
+
durable: false,
|
|
406
|
+
exclusive: false,
|
|
407
|
+
auto_delete: false,
|
|
408
|
+
arguments: nil
|
|
409
409
|
}.merge(h)
|
|
410
410
|
else
|
|
411
411
|
h
|
data/lib/bunny/reader_loop.rb
CHANGED
data/lib/bunny/return_info.rb
CHANGED
|
@@ -41,10 +41,10 @@ module Bunny
|
|
|
41
41
|
# @return [Hash] Hash representation of this returned delivery info
|
|
42
42
|
def to_hash
|
|
43
43
|
@hash ||= {
|
|
44
|
-
:
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
44
|
+
reply_code: @basic_return.reply_code,
|
|
45
|
+
reply_text: @basic_return.reply_text,
|
|
46
|
+
exchange: @basic_return.exchange,
|
|
47
|
+
routing_key: @basic_return.routing_key
|
|
48
48
|
}
|
|
49
49
|
end
|
|
50
50
|
|
data/lib/bunny/session.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "socket"
|
|
4
|
-
require "thread"
|
|
5
|
-
require "monitor"
|
|
6
4
|
|
|
7
5
|
require "bunny/transport"
|
|
8
6
|
require "bunny/channel_id_allocator"
|
|
@@ -51,19 +49,19 @@ module Bunny
|
|
|
51
49
|
|
|
52
50
|
# RabbitMQ client metadata
|
|
53
51
|
DEFAULT_CLIENT_PROPERTIES = {
|
|
54
|
-
:
|
|
55
|
-
:
|
|
56
|
-
:
|
|
57
|
-
:
|
|
52
|
+
capabilities: {
|
|
53
|
+
publisher_confirms: true,
|
|
54
|
+
consumer_cancel_notify: true,
|
|
55
|
+
exchange_exchange_bindings: true,
|
|
58
56
|
:"basic.nack" => true,
|
|
59
57
|
:"connection.blocked" => true,
|
|
60
58
|
# See http://www.rabbitmq.com/auth-notification.html
|
|
61
|
-
:
|
|
59
|
+
authentication_failure_close: true
|
|
62
60
|
},
|
|
63
|
-
:
|
|
64
|
-
:
|
|
65
|
-
:
|
|
66
|
-
:
|
|
61
|
+
product: "Bunny",
|
|
62
|
+
platform: ::RUBY_DESCRIPTION,
|
|
63
|
+
version: Bunny::VERSION,
|
|
64
|
+
information: "https://github.com/ruby-amqp/bunny",
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
# @private
|
|
@@ -225,6 +223,7 @@ module Bunny
|
|
|
225
223
|
@transport_mutex = @mutex_impl.new
|
|
226
224
|
@status_mutex = @mutex_impl.new
|
|
227
225
|
@address_index_mutex = @mutex_impl.new
|
|
226
|
+
@recovery_mutex = @mutex_impl.new
|
|
228
227
|
|
|
229
228
|
@channels = Hash.new
|
|
230
229
|
|
|
@@ -341,6 +340,10 @@ module Bunny
|
|
|
341
340
|
@transport.connect
|
|
342
341
|
end
|
|
343
342
|
|
|
343
|
+
if @transport.read_timeout.nil?
|
|
344
|
+
@transport.read_timeout = @transport.connect_timeout || Transport::DEFAULT_READ_TIMEOUT
|
|
345
|
+
end
|
|
346
|
+
|
|
344
347
|
self.init_connection
|
|
345
348
|
self.open_connection
|
|
346
349
|
|
|
@@ -577,7 +580,7 @@ module Bunny
|
|
|
577
580
|
def queue_exists?(name)
|
|
578
581
|
ch = create_channel
|
|
579
582
|
begin
|
|
580
|
-
ch.queue(name, :
|
|
583
|
+
ch.queue(name, passive: true)
|
|
581
584
|
true
|
|
582
585
|
rescue Bunny::ResourceLocked => _
|
|
583
586
|
true
|
|
@@ -599,7 +602,7 @@ module Bunny
|
|
|
599
602
|
def exchange_exists?(name)
|
|
600
603
|
ch = create_channel
|
|
601
604
|
begin
|
|
602
|
-
ch.exchange(name, :
|
|
605
|
+
ch.exchange(name, passive: true)
|
|
603
606
|
true
|
|
604
607
|
rescue Bunny::NotFound => _
|
|
605
608
|
false
|
|
@@ -786,16 +789,18 @@ module Bunny
|
|
|
786
789
|
# @private
|
|
787
790
|
def handle_frameset(ch_number, frames)
|
|
788
791
|
method = frames.first
|
|
792
|
+
ch = find_channel(ch_number)
|
|
793
|
+
|
|
794
|
+
unless ch
|
|
795
|
+
@logger.warn "Channel #{ch_number} is not open on this connection!"
|
|
796
|
+
return
|
|
797
|
+
end
|
|
789
798
|
|
|
790
799
|
case method
|
|
791
|
-
when AMQ::Protocol::Basic::GetOk
|
|
792
|
-
|
|
793
|
-
when AMQ::Protocol::Basic::
|
|
794
|
-
|
|
795
|
-
when AMQ::Protocol::Basic::Return then
|
|
796
|
-
@channels[ch_number].handle_basic_return(*frames)
|
|
797
|
-
else
|
|
798
|
-
@channels[ch_number].handle_frameset(*frames)
|
|
800
|
+
when AMQ::Protocol::Basic::GetOk then ch.handle_basic_get_ok(*frames)
|
|
801
|
+
when AMQ::Protocol::Basic::GetEmpty then ch.handle_basic_get_empty(*frames)
|
|
802
|
+
when AMQ::Protocol::Basic::Return then ch.handle_basic_return(*frames)
|
|
803
|
+
else ch.handle_frameset(*frames)
|
|
799
804
|
end
|
|
800
805
|
end
|
|
801
806
|
|
|
@@ -810,28 +815,51 @@ module Bunny
|
|
|
810
815
|
|
|
811
816
|
@status_mutex.synchronize { @status = :disconnected }
|
|
812
817
|
|
|
813
|
-
|
|
814
|
-
|
|
818
|
+
acquired = @recovery_mutex.synchronize do
|
|
819
|
+
if @recovering_from_network_failure
|
|
820
|
+
false
|
|
821
|
+
else
|
|
815
822
|
@recovering_from_network_failure = true
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
823
|
+
end
|
|
824
|
+
end
|
|
825
|
+
return unless acquired
|
|
826
|
+
|
|
827
|
+
begin
|
|
828
|
+
if recoverable_network_failure?(exception)
|
|
829
|
+
announce_network_failure_recovery
|
|
830
|
+
@channel_mutex.synchronize do
|
|
831
|
+
@channels.each do |n, ch|
|
|
832
|
+
ch.connection_closed!
|
|
833
|
+
ch.maybe_kill_consumer_work_pool!
|
|
822
834
|
end
|
|
823
|
-
|
|
824
|
-
|
|
835
|
+
end
|
|
836
|
+
@reader_loop.stop if @reader_loop
|
|
837
|
+
maybe_shutdown_heartbeat_sender
|
|
838
|
+
|
|
839
|
+
loop do
|
|
840
|
+
break unless recover_connection_and_channels
|
|
825
841
|
|
|
826
|
-
recover_connection_and_channels
|
|
827
842
|
recover_topology
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
843
|
+
|
|
844
|
+
if open?
|
|
845
|
+
mark_channels_after_recovery!
|
|
846
|
+
notify_of_recovery_completion
|
|
847
|
+
break
|
|
848
|
+
end
|
|
849
|
+
|
|
850
|
+
if should_retry_recovery?
|
|
851
|
+
decrement_recovery_attemp_counter!
|
|
852
|
+
announce_network_failure_recovery
|
|
853
|
+
else
|
|
854
|
+
give_up_on_recovery
|
|
855
|
+
break
|
|
856
|
+
end
|
|
831
857
|
end
|
|
832
|
-
|
|
833
|
-
@
|
|
858
|
+
else
|
|
859
|
+
@logger.error "Exception #{exception.message} is considered unrecoverable..."
|
|
834
860
|
end
|
|
861
|
+
ensure
|
|
862
|
+
@recovery_mutex.synchronize { @recovering_from_network_failure = false }
|
|
835
863
|
end
|
|
836
864
|
end
|
|
837
865
|
|
|
@@ -844,7 +872,7 @@ module Bunny
|
|
|
844
872
|
# @return [Boolean]
|
|
845
873
|
# @private
|
|
846
874
|
def recovering_from_network_failure?
|
|
847
|
-
@recovering_from_network_failure
|
|
875
|
+
@recovery_mutex.synchronize { @recovering_from_network_failure }
|
|
848
876
|
end
|
|
849
877
|
|
|
850
878
|
# @param [Bunny::Queue] queue
|
|
@@ -985,7 +1013,6 @@ module Bunny
|
|
|
985
1013
|
self.start
|
|
986
1014
|
|
|
987
1015
|
if open?
|
|
988
|
-
@recovering_from_network_failure = false
|
|
989
1016
|
@logger.debug "Connection is now open"
|
|
990
1017
|
if @reset_recovery_attempt_counter_after_reconnection
|
|
991
1018
|
@logger.debug "Resetting recovery attempt counter after successful reconnection"
|
|
@@ -995,6 +1022,9 @@ module Bunny
|
|
|
995
1022
|
end
|
|
996
1023
|
|
|
997
1024
|
recover_channels
|
|
1025
|
+
true
|
|
1026
|
+
else
|
|
1027
|
+
raise TCPConnectionFailed.new("connection is not open after a connection recovery attempt", @transport.host, @transport.port)
|
|
998
1028
|
end
|
|
999
1029
|
rescue HostListDepleted
|
|
1000
1030
|
reset_address_index
|
|
@@ -1008,17 +1038,23 @@ module Bunny
|
|
|
1008
1038
|
announce_network_failure_recovery
|
|
1009
1039
|
retry
|
|
1010
1040
|
else
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
self.close(false)
|
|
1014
|
-
@manually_closed = false
|
|
1015
|
-
notify_of_recovery_attempts_exhausted
|
|
1041
|
+
give_up_on_recovery
|
|
1042
|
+
false
|
|
1016
1043
|
end
|
|
1017
1044
|
else
|
|
1018
1045
|
raise e
|
|
1019
1046
|
end
|
|
1020
1047
|
end
|
|
1021
1048
|
|
|
1049
|
+
# @private
|
|
1050
|
+
def give_up_on_recovery
|
|
1051
|
+
@logger.error "Ran out of recovery attempts (limit set to #{@max_recovery_attempts}), giving up"
|
|
1052
|
+
@transport.close
|
|
1053
|
+
self.close(false)
|
|
1054
|
+
@manually_closed = false
|
|
1055
|
+
notify_of_recovery_attempts_exhausted
|
|
1056
|
+
end
|
|
1057
|
+
|
|
1022
1058
|
# @private
|
|
1023
1059
|
def recovery_attempts_limited?
|
|
1024
1060
|
!!@max_recovery_attempts
|
|
@@ -1048,11 +1084,21 @@ module Bunny
|
|
|
1048
1084
|
@channel_mutex.synchronize do
|
|
1049
1085
|
@channels.each do |n, ch|
|
|
1050
1086
|
ch.open
|
|
1087
|
+
ch.recovering!
|
|
1051
1088
|
ch.recover_from_network_failure
|
|
1052
1089
|
end
|
|
1053
1090
|
end
|
|
1054
1091
|
end
|
|
1055
1092
|
|
|
1093
|
+
# @private
|
|
1094
|
+
def mark_channels_after_recovery!
|
|
1095
|
+
@channel_mutex.synchronize do
|
|
1096
|
+
@channels.each do |n, ch|
|
|
1097
|
+
ch.recovery_completed!
|
|
1098
|
+
end
|
|
1099
|
+
end
|
|
1100
|
+
end
|
|
1101
|
+
|
|
1056
1102
|
# @private
|
|
1057
1103
|
def recover_topology
|
|
1058
1104
|
@logger.debug "Will recover topology now"
|
|
@@ -1079,7 +1125,7 @@ module Bunny
|
|
|
1079
1125
|
exchanges.each do |x|
|
|
1080
1126
|
begin
|
|
1081
1127
|
recover_exchange(x)
|
|
1082
|
-
rescue
|
|
1128
|
+
rescue ::StandardError => e
|
|
1083
1129
|
@logger.error "Caught an exception while recovering exchange #{x.name}: #{e.inspect}"
|
|
1084
1130
|
end
|
|
1085
1131
|
end
|
|
@@ -1088,7 +1134,7 @@ module Bunny
|
|
|
1088
1134
|
queues.each do |q|
|
|
1089
1135
|
begin
|
|
1090
1136
|
recover_queue(q)
|
|
1091
|
-
rescue
|
|
1137
|
+
rescue ::StandardError => e
|
|
1092
1138
|
@logger.error "Caught an exception while recovering queue #{q.name}: #{e.inspect}"
|
|
1093
1139
|
end
|
|
1094
1140
|
end
|
|
@@ -1097,7 +1143,7 @@ module Bunny
|
|
|
1097
1143
|
queue_bindings.each do |b|
|
|
1098
1144
|
begin
|
|
1099
1145
|
recover_queue_binding(b)
|
|
1100
|
-
rescue
|
|
1146
|
+
rescue ::StandardError => e
|
|
1101
1147
|
@logger.error "Caught an exception while recovering a binding of queue #{b.destination}: #{e.inspect}"
|
|
1102
1148
|
end
|
|
1103
1149
|
end
|
|
@@ -1105,14 +1151,18 @@ module Bunny
|
|
|
1105
1151
|
exchange_bindings.each do |b|
|
|
1106
1152
|
begin
|
|
1107
1153
|
recover_exchange_binding(b)
|
|
1108
|
-
rescue
|
|
1154
|
+
rescue ::StandardError => e
|
|
1109
1155
|
@logger.error "Caught an exception while recovering a binding of exchange #{b.source}: #{e.inspect}"
|
|
1110
1156
|
end
|
|
1111
1157
|
end
|
|
1112
1158
|
|
|
1113
1159
|
@logger.debug { "Will recover #{consumers.size} consumer(s)" }
|
|
1114
1160
|
consumers.each do |c|
|
|
1115
|
-
|
|
1161
|
+
begin
|
|
1162
|
+
recover_consumer(c)
|
|
1163
|
+
rescue ::StandardError => e
|
|
1164
|
+
@logger.error "Caught an exception while recovering consumer #{c.consumer_tag} on queue #{c.queue_name}: #{e.inspect}"
|
|
1165
|
+
end
|
|
1116
1166
|
end
|
|
1117
1167
|
end
|
|
1118
1168
|
|
|
@@ -1183,8 +1233,12 @@ module Bunny
|
|
|
1183
1233
|
# @private
|
|
1184
1234
|
def recover_consumer(c)
|
|
1185
1235
|
c.channel.maybe_reinitialize_consumer_pool!
|
|
1186
|
-
c.
|
|
1187
|
-
c.
|
|
1236
|
+
if c.callable.is_a?(Bunny::Consumer)
|
|
1237
|
+
c.channel.basic_consume_with(c.callable)
|
|
1238
|
+
else
|
|
1239
|
+
c.channel.basic_consume(c.queue_name, c.consumer_tag, !c.manual_ack, c.exclusive, c.arguments) do |*args|
|
|
1240
|
+
c.callable.call(*args)
|
|
1241
|
+
end
|
|
1188
1242
|
end
|
|
1189
1243
|
end
|
|
1190
1244
|
|
|
@@ -1601,9 +1655,11 @@ module Bunny
|
|
|
1601
1655
|
# We set the read_write_timeout to twice the heartbeat value,
|
|
1602
1656
|
# and then some padding for edge cases.
|
|
1603
1657
|
# This allows us to miss a single heartbeat before we time out the socket.
|
|
1604
|
-
# If heartbeats are disabled,
|
|
1605
|
-
#
|
|
1606
|
-
|
|
1658
|
+
# If heartbeats are disabled, socket read timeouts will be disabled as well,
|
|
1659
|
+
# but only after negotiation completes: a peer that accepts TCP connections
|
|
1660
|
+
# without servicing them must not be able to block the handshake
|
|
1661
|
+
# indefinitely. See ruby-amqp/bunny#551.
|
|
1662
|
+
@transport.read_timeout = @heartbeat * 2.2 if @heartbeat > 0
|
|
1607
1663
|
@logger.debug { "Will use socket read timeout of #{@transport.read_timeout.to_i} seconds" }
|
|
1608
1664
|
|
|
1609
1665
|
# if there are existing channels we've just recovered from
|
|
@@ -1634,27 +1690,28 @@ module Bunny
|
|
|
1634
1690
|
end
|
|
1635
1691
|
connection_open_ok = frame2.decode_payload
|
|
1636
1692
|
|
|
1637
|
-
@status_mutex.synchronize { @status = :open }
|
|
1638
|
-
if @heartbeat && @heartbeat > 0
|
|
1639
|
-
initialize_heartbeat_sender
|
|
1640
|
-
end
|
|
1641
|
-
|
|
1642
1693
|
unless connection_open_ok.is_a?(AMQ::Protocol::Connection::OpenOk)
|
|
1643
1694
|
if connection_open_ok.is_a?(AMQ::Protocol::Connection::Close)
|
|
1644
1695
|
e = instantiate_connection_level_exception(connection_open_ok)
|
|
1696
|
+
if automatically_recover?
|
|
1697
|
+
close_transport
|
|
1698
|
+
raise e
|
|
1699
|
+
end
|
|
1700
|
+
|
|
1645
1701
|
begin
|
|
1646
1702
|
shut_down_all_consumer_work_pools!
|
|
1647
1703
|
maybe_shutdown_reader_loop
|
|
1648
1704
|
rescue ShutdownSignal => _sse
|
|
1649
1705
|
# no-op
|
|
1650
|
-
rescue Exception =>
|
|
1651
|
-
@logger.warn "Caught an exception when cleaning up after receiving connection.close: #{
|
|
1706
|
+
rescue Exception => cleanup_exception
|
|
1707
|
+
@logger.warn "Caught an exception when cleaning up after receiving connection.close: #{cleanup_exception.message}"
|
|
1652
1708
|
ensure
|
|
1653
1709
|
close_transport
|
|
1654
1710
|
end
|
|
1655
1711
|
|
|
1656
1712
|
if threaded?
|
|
1657
1713
|
@session_error_handler.raise(e)
|
|
1714
|
+
return
|
|
1658
1715
|
else
|
|
1659
1716
|
raise e
|
|
1660
1717
|
end
|
|
@@ -1662,6 +1719,13 @@ module Bunny
|
|
|
1662
1719
|
raise "could not open connection: server did not respond with connection.open-ok but #{connection_open_ok.inspect} instead"
|
|
1663
1720
|
end
|
|
1664
1721
|
end
|
|
1722
|
+
|
|
1723
|
+
@status_mutex.synchronize { @status = :open }
|
|
1724
|
+
if @heartbeat && @heartbeat > 0
|
|
1725
|
+
initialize_heartbeat_sender
|
|
1726
|
+
else
|
|
1727
|
+
@transport.read_timeout = 0
|
|
1728
|
+
end
|
|
1665
1729
|
end
|
|
1666
1730
|
|
|
1667
1731
|
def heartbeat_disabled?(val)
|
|
@@ -1702,7 +1766,7 @@ module Bunny
|
|
|
1702
1766
|
@transport = Transport.new(self,
|
|
1703
1767
|
host_from_address(address),
|
|
1704
1768
|
port_from_address(address),
|
|
1705
|
-
@opts.merge(:
|
|
1769
|
+
@opts.merge(session_error_handler: @session_error_handler)
|
|
1706
1770
|
)
|
|
1707
1771
|
|
|
1708
1772
|
# Reset the cached progname for the logger only when no logger was provided
|
data/lib/bunny/transport.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "socket"
|
|
4
|
-
require "thread"
|
|
5
|
-
require "monitor"
|
|
6
4
|
|
|
7
5
|
begin
|
|
8
6
|
require "openssl"
|
|
@@ -305,7 +303,7 @@ module Bunny
|
|
|
305
303
|
def self.reachable?(host, port, timeout)
|
|
306
304
|
begin
|
|
307
305
|
s = Bunny::SocketImpl.open(host, port,
|
|
308
|
-
:
|
|
306
|
+
connect_timeout: timeout)
|
|
309
307
|
|
|
310
308
|
true
|
|
311
309
|
rescue SocketError, Timeout::Error => _e
|
|
@@ -327,8 +325,8 @@ module Bunny
|
|
|
327
325
|
@logger.debug("Using connection timeout of #{@connect_timeout} when connecting to #{@host}:#{@port}")
|
|
328
326
|
begin
|
|
329
327
|
@socket = Bunny::SocketImpl.open(@host, @port,
|
|
330
|
-
:
|
|
331
|
-
:
|
|
328
|
+
keepalive: @opts[:keepalive],
|
|
329
|
+
connect_timeout: @connect_timeout)
|
|
332
330
|
rescue StandardError, ClientTimeout => e
|
|
333
331
|
@status = :not_connected
|
|
334
332
|
raise Bunny::TCPConnectionFailed.new(e, self.hostname, self.port)
|
data/lib/bunny/version.rb
CHANGED
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: 3.
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Duncan
|
|
@@ -19,14 +19,14 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - "~>"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '2.
|
|
22
|
+
version: '2.8'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - "~>"
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '2.
|
|
29
|
+
version: '2.8'
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: logger
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -76,6 +76,8 @@ extensions: []
|
|
|
76
76
|
extra_rdoc_files:
|
|
77
77
|
- README.md
|
|
78
78
|
files:
|
|
79
|
+
- ChangeLog.md
|
|
80
|
+
- LICENSE
|
|
79
81
|
- README.md
|
|
80
82
|
- lib/amq/protocol/extensions.rb
|
|
81
83
|
- lib/bunny.rb
|
|
@@ -127,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
127
129
|
requirements:
|
|
128
130
|
- - ">="
|
|
129
131
|
- !ruby/object:Gem::Version
|
|
130
|
-
version: '
|
|
132
|
+
version: '3.0'
|
|
131
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
134
|
requirements:
|
|
133
135
|
- - ">="
|
|
134
136
|
- !ruby/object:Gem::Version
|
|
135
137
|
version: '0'
|
|
136
138
|
requirements: []
|
|
137
|
-
rubygems_version:
|
|
139
|
+
rubygems_version: 3.6.9
|
|
138
140
|
specification_version: 4
|
|
139
141
|
summary: Popular easy to use Ruby client for RabbitMQ
|
|
140
142
|
test_files: []
|