bunny 2.24.0 → 3.1.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/README.md +15 -9
- data/lib/bunny/channel.rb +727 -124
- data/lib/bunny/concurrent/exception_accumulator.rb +115 -0
- data/lib/bunny/consumer.rb +2 -11
- data/lib/bunny/cruby/socket.rb +33 -1
- data/lib/bunny/cruby/ssl_socket.rb +41 -0
- data/lib/bunny/delivery_info.rb +22 -16
- data/lib/bunny/exceptions.rb +31 -2
- data/lib/bunny/exchange.rb +25 -13
- data/lib/bunny/get_response.rb +19 -15
- data/lib/bunny/heartbeat_sender.rb +2 -2
- data/lib/bunny/queue.rb +22 -38
- data/lib/bunny/reader_loop.rb +6 -6
- data/lib/bunny/return_info.rb +16 -11
- data/lib/bunny/session.rb +388 -36
- data/lib/bunny/timestamp.rb +1 -1
- data/lib/bunny/topology_recovery_filter.rb +71 -0
- data/lib/bunny/topology_registry.rb +824 -0
- data/lib/bunny/transport.rb +36 -9
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +1 -1
- metadata +29 -7
- data/lib/bunny/versioned_delivery_tag.rb +0 -30
data/lib/bunny/transport.rb
CHANGED
|
@@ -72,7 +72,7 @@ module Bunny
|
|
|
72
72
|
@read_timeout = opts[:read_timeout] || DEFAULT_READ_TIMEOUT
|
|
73
73
|
@read_timeout = nil if @read_timeout == 0
|
|
74
74
|
|
|
75
|
-
@write_timeout = opts[:socket_timeout] # Backwards
|
|
75
|
+
@write_timeout = opts[:socket_timeout] # Backwards compatibility
|
|
76
76
|
|
|
77
77
|
@write_timeout ||= opts[:write_timeout] || DEFAULT_WRITE_TIMEOUT
|
|
78
78
|
@write_timeout = nil if @write_timeout == 0
|
|
@@ -180,8 +180,10 @@ module Bunny
|
|
|
180
180
|
# Writes data to the socket without timeout checks
|
|
181
181
|
def write_without_timeout(data, raise_exceptions = false)
|
|
182
182
|
begin
|
|
183
|
-
@writes_mutex.synchronize
|
|
184
|
-
|
|
183
|
+
@writes_mutex.synchronize do
|
|
184
|
+
@socket.write(data)
|
|
185
|
+
@socket.flush
|
|
186
|
+
end
|
|
185
187
|
rescue SystemCallError, Bunny::ConnectionError, IOError => e
|
|
186
188
|
close
|
|
187
189
|
raise e if raise_exceptions
|
|
@@ -200,7 +202,7 @@ module Bunny
|
|
|
200
202
|
# @private
|
|
201
203
|
def send_frame(frame)
|
|
202
204
|
if closed?
|
|
203
|
-
@session.handle_network_failure(ConnectionClosedError.new(frame))
|
|
205
|
+
@session.handle_network_failure(ConnectionClosedError.new(frame)) if @session.automatically_recover?
|
|
204
206
|
else
|
|
205
207
|
write(frame.encode)
|
|
206
208
|
end
|
|
@@ -212,7 +214,7 @@ module Bunny
|
|
|
212
214
|
# @private
|
|
213
215
|
def send_frame_without_timeout(frame)
|
|
214
216
|
if closed?
|
|
215
|
-
@session.handle_network_failure(ConnectionClosedError.new(frame))
|
|
217
|
+
@session.handle_network_failure(ConnectionClosedError.new(frame)) if @session.automatically_recover?
|
|
216
218
|
else
|
|
217
219
|
write_without_timeout(frame.encode)
|
|
218
220
|
end
|
|
@@ -259,7 +261,10 @@ module Bunny
|
|
|
259
261
|
# Exposed primarily for Bunny::Channel
|
|
260
262
|
# @private
|
|
261
263
|
def read_next_frame(opts = {})
|
|
262
|
-
|
|
264
|
+
@frame_header_buffer ||= String.new(capacity: 7)
|
|
265
|
+
@frame_header_buffer.clear
|
|
266
|
+
header = read_fully_into(@frame_header_buffer, 7)
|
|
267
|
+
|
|
263
268
|
type, channel, size = AMQ::Protocol::Frame.decode_header(header)
|
|
264
269
|
payload = if size > 0
|
|
265
270
|
read_fully(size)
|
|
@@ -278,8 +283,26 @@ module Bunny
|
|
|
278
283
|
AMQ::Protocol::Frame.new(type, payload, channel)
|
|
279
284
|
end
|
|
280
285
|
|
|
286
|
+
# @private
|
|
287
|
+
def read_fully_into(buffer, count)
|
|
288
|
+
begin
|
|
289
|
+
@socket.read_fully_into(buffer, count, @read_timeout)
|
|
290
|
+
rescue SystemCallError, Timeout::Error, Bunny::ConnectionError, IOError => e
|
|
291
|
+
@logger.error "Got an exception when receiving data: #{e.message} (#{e.class.name})"
|
|
292
|
+
close
|
|
293
|
+
@status = :not_connected
|
|
281
294
|
|
|
282
|
-
|
|
295
|
+
if @session.automatically_recover?
|
|
296
|
+
raise
|
|
297
|
+
else
|
|
298
|
+
@session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
buffer
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def self.reachable?(host, port, timeout)
|
|
283
306
|
begin
|
|
284
307
|
s = Bunny::SocketImpl.open(host, port,
|
|
285
308
|
:connect_timeout => timeout)
|
|
@@ -292,12 +315,16 @@ module Bunny
|
|
|
292
315
|
end
|
|
293
316
|
end
|
|
294
317
|
|
|
318
|
+
class << self
|
|
319
|
+
alias_method :reacheable?, :reachable?
|
|
320
|
+
end
|
|
321
|
+
|
|
295
322
|
def self.ping!(host, port, timeout)
|
|
296
|
-
raise ConnectionTimeout.new("#{host}:#{port} is unreachable") if !
|
|
323
|
+
raise ConnectionTimeout.new("#{host}:#{port} is unreachable") if !reachable?(host, port, timeout)
|
|
297
324
|
end
|
|
298
325
|
|
|
299
326
|
def initialize_socket
|
|
300
|
-
@logger.debug("
|
|
327
|
+
@logger.debug("Using connection timeout of #{@connect_timeout} when connecting to #{@host}:#{@port}")
|
|
301
328
|
begin
|
|
302
329
|
@socket = Bunny::SocketImpl.open(@host, @port,
|
|
303
330
|
:keepalive => @opts[:keepalive],
|
data/lib/bunny/version.rb
CHANGED
data/lib/bunny.rb
CHANGED
|
@@ -89,7 +89,7 @@ module Bunny
|
|
|
89
89
|
# @option connection_string_or_opts [Proc] :recovery_attempt_started (nil) Will be called before every connection recovery attempt
|
|
90
90
|
# @option connection_string_or_opts [Proc] :recovery_completed (nil) Will be called after successful connection recovery
|
|
91
91
|
# @option connection_string_or_opts [Boolean] :recover_from_connection_close (true) Should this connection recover after receiving a server-sent connection.close (e.g. connection was force closed)?
|
|
92
|
-
# @option connection_string_or_opts [Object] :session_error_handler (
|
|
92
|
+
# @option connection_string_or_opts [Object] :session_error_handler (ExceptionAccumulator.new) Object which responds to #raise that will act as a session error handler. Defaults to a Bunny::ExceptionAccumulator instance which stores exceptions for safe retrieval later. Can be set to Thread.current for legacy behavior (raises asynchronous exceptions in the creating thread).
|
|
93
93
|
#
|
|
94
94
|
# @option optz [String] :auth_mechanism ("PLAIN") Authentication mechanism, PLAIN or EXTERNAL
|
|
95
95
|
# @option optz [String] :locale ("PLAIN") Locale RabbitMQ should use
|
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:
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Duncan
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
- Stefan Kaes
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date:
|
|
14
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: amq-protocol
|
|
@@ -19,14 +19,34 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - "~>"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '2.
|
|
22
|
+
version: '2.7'
|
|
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.7'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: logger
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - "~>"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '1'
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.7'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1'
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '1.7'
|
|
30
50
|
- !ruby/object:Gem::Dependency
|
|
31
51
|
name: sorted_set
|
|
32
52
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,6 +87,7 @@ files:
|
|
|
67
87
|
- lib/bunny/concurrent/atomic_fixnum.rb
|
|
68
88
|
- lib/bunny/concurrent/condition.rb
|
|
69
89
|
- lib/bunny/concurrent/continuation_queue.rb
|
|
90
|
+
- lib/bunny/concurrent/exception_accumulator.rb
|
|
70
91
|
- lib/bunny/concurrent/synchronized_sorted_set.rb
|
|
71
92
|
- lib/bunny/consumer.rb
|
|
72
93
|
- lib/bunny/consumer_tag_generator.rb
|
|
@@ -89,9 +110,10 @@ files:
|
|
|
89
110
|
- lib/bunny/test_kit.rb
|
|
90
111
|
- lib/bunny/timeout.rb
|
|
91
112
|
- lib/bunny/timestamp.rb
|
|
113
|
+
- lib/bunny/topology_recovery_filter.rb
|
|
114
|
+
- lib/bunny/topology_registry.rb
|
|
92
115
|
- lib/bunny/transport.rb
|
|
93
116
|
- lib/bunny/version.rb
|
|
94
|
-
- lib/bunny/versioned_delivery_tag.rb
|
|
95
117
|
homepage: http://rubybunny.info
|
|
96
118
|
licenses:
|
|
97
119
|
- MIT
|
|
@@ -105,14 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
105
127
|
requirements:
|
|
106
128
|
- - ">="
|
|
107
129
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '
|
|
130
|
+
version: '3.0'
|
|
109
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
132
|
requirements:
|
|
111
133
|
- - ">="
|
|
112
134
|
- !ruby/object:Gem::Version
|
|
113
135
|
version: '0'
|
|
114
136
|
requirements: []
|
|
115
|
-
rubygems_version:
|
|
137
|
+
rubygems_version: 4.0.6
|
|
116
138
|
specification_version: 4
|
|
117
139
|
summary: Popular easy to use Ruby client for RabbitMQ
|
|
118
140
|
test_files: []
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Bunny
|
|
4
|
-
# Wraps a delivery tag (which is an integer) so that {Bunny::Channel} could
|
|
5
|
-
# detect stale tags after connection recovery.
|
|
6
|
-
#
|
|
7
|
-
# @private
|
|
8
|
-
class VersionedDeliveryTag
|
|
9
|
-
attr_reader :tag
|
|
10
|
-
attr_reader :version
|
|
11
|
-
|
|
12
|
-
def initialize(tag, version)
|
|
13
|
-
raise ArgumentError.new("tag cannot be nil") unless tag
|
|
14
|
-
raise ArgumentError.new("version cannot be nil") unless version
|
|
15
|
-
|
|
16
|
-
@tag = tag.to_i
|
|
17
|
-
@version = version.to_i
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def to_i
|
|
21
|
-
@tag
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def stale?(version)
|
|
25
|
-
raise ArgumentError.new("version cannot be nil") unless version
|
|
26
|
-
|
|
27
|
-
@version < version.to_i
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|