bunny 3.1.0 → 3.3.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.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009–2023 Chris Duncan, Jakub Stastny aka botanicus,
2
+ Michael S. Klishin, Eric Lindvall, Stefan Kaes and contributors.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/bunny/channel.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
3
 
4
- require "thread"
5
- require "monitor"
6
4
  require "set"
7
5
 
8
6
  require "bunny/concurrent/atomic_fixnum"
@@ -112,8 +110,8 @@ module Bunny
112
110
  # ch2 = conn.create_channel
113
111
  # q = "bunny.examples.recovery.q#{rand}"
114
112
  #
115
- # ch2.queue_declare(q, :durable => false)
116
- # ch2.queue_declare(q, :durable => true)
113
+ # ch2.queue_declare(q, durable: false)
114
+ # ch2.queue_declare(q, durable: true)
117
115
  # rescue Bunny::PreconditionFailed => e
118
116
  # puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
119
117
  # ensure
@@ -521,11 +519,11 @@ module Bunny
521
519
  # @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
522
520
  # @api public
523
521
  def queue(name = AMQ::Protocol::EMPTY_STRING, opts = {})
524
- throw ArgumentError.new("queue name must not be nil") if name.nil?
522
+ raise ArgumentError, "queue name must not be nil" if name.nil?
525
523
 
526
524
  q = find_queue(name) || Bunny::Queue.new(self, name, opts)
527
525
 
528
- record_queue(q)
526
+ record_queue(q) unless opts[:passive]
529
527
  register_queue(q)
530
528
  end
531
529
 
@@ -541,8 +539,8 @@ module Bunny
541
539
  # @see #queue
542
540
  # @api public
543
541
  def quorum_queue(name, opts = {})
544
- throw ArgumentError.new("quorum queue name must not be nil") if name.nil?
545
- throw ArgumentError.new("quorum queue name must not be empty (server-named QQs do not make sense)") if name.empty?
542
+ raise ArgumentError, "quorum queue name must not be nil" if name.nil?
543
+ raise ArgumentError, "quorum queue name must not be empty (server-named QQs do not make sense)" if name.empty?
546
544
 
547
545
  durable_queue(name, Bunny::Queue::Types::QUORUM, opts)
548
546
  end
@@ -563,8 +561,8 @@ module Bunny
563
561
  # @see #queue
564
562
  # @api public
565
563
  def stream(name, opts = {})
566
- throw ArgumentError.new("stream name must not be nil") if name.nil?
567
- throw ArgumentError.new("stream name must not be empty (server-named QQs do not make sense)") if name.empty?
564
+ raise ArgumentError, "stream name must not be nil" if name.nil?
565
+ raise ArgumentError, "stream name must not be empty (server-named QQs do not make sense)" if name.empty?
568
566
 
569
567
  durable_queue(name, Bunny::Queue::Types::STREAM, opts)
570
568
  end
@@ -585,15 +583,15 @@ module Bunny
585
583
  # @see #queue
586
584
  # @api public
587
585
  def delayed_queue(name, opts = {})
588
- throw ArgumentError.new("delayed queue name must not be nil") if name.nil?
589
- throw ArgumentError.new("delayed queue name must not be empty") if name.empty?
586
+ raise ArgumentError, "delayed queue name must not be nil" if name.nil?
587
+ raise ArgumentError, "delayed queue name must not be empty" if name.empty?
590
588
 
591
589
  args = opts[:arguments] || {}
592
590
  args[Bunny::Queue::XArgs::DELAYED_RETRY_TYPE] = opts[:delayed_retry_type] if opts[:delayed_retry_type]
593
591
  args[Bunny::Queue::XArgs::DELAYED_RETRY_MIN] = opts[:delayed_retry_min] if opts[:delayed_retry_min]
594
592
  args[Bunny::Queue::XArgs::DELAYED_RETRY_MAX] = opts[:delayed_retry_max] if opts[:delayed_retry_max]
595
593
 
596
- final_opts = opts.merge(:arguments => args)
594
+ final_opts = opts.merge(arguments: args)
597
595
  final_opts.delete(:delayed_retry_type)
598
596
  final_opts.delete(:delayed_retry_min)
599
597
  final_opts.delete(:delayed_retry_max)
@@ -616,14 +614,14 @@ module Bunny
616
614
  # @see #queue
617
615
  # @api public
618
616
  def jms_queue(name, opts = {})
619
- throw ArgumentError.new("JMS queue name must not be nil") if name.nil?
620
- throw ArgumentError.new("JMS queue name must not be empty") if name.empty?
617
+ raise ArgumentError, "JMS queue name must not be nil" if name.nil?
618
+ raise ArgumentError, "JMS queue name must not be empty" if name.empty?
621
619
 
622
620
  args = opts[:arguments] || {}
623
621
  args[Bunny::Queue::XArgs::SELECTOR_FIELDS] = opts[:selector_fields] if opts[:selector_fields]
624
622
  args[Bunny::Queue::XArgs::SELECTOR_FIELD_MAX_BYTES] = opts[:selector_field_max_bytes] if opts[:selector_field_max_bytes]
625
623
 
626
- final_opts = opts.merge(:arguments => args)
624
+ final_opts = opts.merge(arguments: args)
627
625
  final_opts.delete(:selector_fields)
628
626
  final_opts.delete(:selector_field_max_bytes)
629
627
 
@@ -642,16 +640,16 @@ module Bunny
642
640
  # @see #queue
643
641
  # @api public
644
642
  def durable_queue(name, type = "classic", opts = {})
645
- throw ArgumentError.new("queue name must not be nil") if name.nil?
646
- throw ArgumentError.new("queue name must not be empty (server-named durable queues do not make sense)") if name.empty?
643
+ raise ArgumentError, "queue name must not be nil" if name.nil?
644
+ raise ArgumentError, "queue name must not be empty (server-named durable queues do not make sense)" if name.empty?
647
645
 
648
- final_opts = opts.merge({
649
- :type => type,
650
- :durable => true,
646
+ final_opts = opts.merge(
647
+ type: type,
648
+ durable: true,
651
649
  # exclusive or auto-delete QQs do not make much sense
652
- :exclusive => false,
653
- :auto_delete => false
654
- })
650
+ exclusive: false,
651
+ auto_delete: false
652
+ )
655
653
  q = find_queue(name) || Bunny::Queue.new(self, name, final_opts)
656
654
 
657
655
  record_queue(q)
@@ -666,7 +664,7 @@ module Bunny
666
664
  # @api public
667
665
  def temporary_queue(opts = {})
668
666
  temporary_queue_opts = {
669
- :exclusive => true
667
+ exclusive: true
670
668
  }
671
669
  queue("", opts.merge(temporary_queue_opts))
672
670
  end
@@ -773,11 +771,7 @@ module Bunny
773
771
  raise_if_no_longer_open!
774
772
  raise ArgumentError, "routing key cannot be longer than #{SHORTSTR_LIMIT} characters" if routing_key && routing_key.size > SHORTSTR_LIMIT
775
773
 
776
- exchange_name = if exchange.respond_to?(:name)
777
- exchange.name
778
- else
779
- exchange
780
- end
774
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
781
775
 
782
776
  mode = if opts.fetch(:persistent, true)
783
777
  2
@@ -848,11 +842,7 @@ module Bunny
848
842
  raise ArgumentError, "routing key cannot be longer than #{SHORTSTR_LIMIT} characters" if routing_key && routing_key.size > SHORTSTR_LIMIT
849
843
  return self if payloads.empty?
850
844
 
851
- exchange_name = if exchange.respond_to?(:name)
852
- exchange.name
853
- else
854
- exchange
855
- end
845
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
856
846
 
857
847
  mode = opts.fetch(:persistent, true) ? 2 : 1
858
848
  opts = opts.dup
@@ -922,12 +912,12 @@ module Bunny
922
912
  # conn.start
923
913
  # ch = conn.create_channel
924
914
  # # here we assume the queue already exists and has messages
925
- # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue1", :manual_ack => true)
915
+ # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue1", manual_ack: true)
926
916
  # ch.acknowledge(delivery_info.delivery_tag)
927
917
  # @see Bunny::Queue#pop
928
918
  # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
929
919
  # @api public
930
- def basic_get(queue, opts = {:manual_ack => true})
920
+ def basic_get(queue, opts = { manual_ack: true })
931
921
  raise_if_no_longer_open!
932
922
 
933
923
  unless opts[:ack].nil?
@@ -1046,7 +1036,7 @@ module Bunny
1046
1036
  #
1047
1037
  # ch = conn.create_channel
1048
1038
  # # we assume the queue exists and has messages
1049
- # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1039
+ # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1050
1040
  # ch.basic_reject(delivery_info.delivery_tag, true)
1051
1041
  #
1052
1042
  # @see Bunny::Channel#basic_nack
@@ -1081,7 +1071,7 @@ module Bunny
1081
1071
  #
1082
1072
  # ch = conn.create_channel
1083
1073
  # # we assume the queue exists and has messages
1084
- # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1074
+ # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1085
1075
  # ch.basic_ack(delivery_info.delivery_tag.to_i)
1086
1076
  #
1087
1077
  # @example Ack multiple messages fetched via basic.get
@@ -1090,9 +1080,9 @@ module Bunny
1090
1080
  #
1091
1081
  # ch = conn.create_channel
1092
1082
  # # we assume the queue exists and has messages
1093
- # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1094
- # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1095
- # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1083
+ # _, _, payload1 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1084
+ # _, _, payload2 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1085
+ # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1096
1086
  # # ack all fetched messages up to payload3
1097
1087
  # ch.basic_ack(delivery_info.delivery_tag.to_i, true)
1098
1088
  #
@@ -1141,7 +1131,7 @@ module Bunny
1141
1131
  #
1142
1132
  # ch = conn.create_channel
1143
1133
  # # we assume the queue exists and has messages
1144
- # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1134
+ # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1145
1135
  # ch.basic_nack(delivery_info.delivery_tag, false, true)
1146
1136
  #
1147
1137
  #
@@ -1151,9 +1141,9 @@ module Bunny
1151
1141
  #
1152
1142
  # ch = conn.create_channel
1153
1143
  # # we assume the queue exists and has messages
1154
- # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1155
- # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1156
- # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1144
+ # _, _, payload1 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1145
+ # _, _, payload2 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1146
+ # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", manual_ack: true)
1157
1147
  # # requeue all fetched messages up to payload3
1158
1148
  # ch.basic_nack(delivery_info.delivery_tag, true, true)
1159
1149
  #
@@ -1189,11 +1179,7 @@ module Bunny
1189
1179
  raise_if_no_longer_open!
1190
1180
  maybe_start_consumer_work_pool!
1191
1181
 
1192
- queue_name = if queue.respond_to?(:name)
1193
- queue.name
1194
- else
1195
- queue
1196
- end
1182
+ queue_name = queue.is_a?(Bunny::Queue) ? queue.name : queue
1197
1183
 
1198
1184
  # helps avoid race condition between basic.consume-ok and basic.deliver if there are messages
1199
1185
  # in the queue already. MK.
@@ -1366,7 +1352,7 @@ module Bunny
1366
1352
  args = opts[:arguments]
1367
1353
 
1368
1354
  result = self.queue_declare_without_recording_topology(name, opts)
1369
- self.record_queue_with(self, result.queue, is_server_named, durable, exclusive, auto_delete, args) unless passive
1355
+ self.record_queue_with(self, result.queue, is_server_named, durable, auto_delete, exclusive, args) unless passive
1370
1356
 
1371
1357
  result
1372
1358
  end
@@ -1479,11 +1465,7 @@ module Bunny
1479
1465
  def queue_bind(name, exchange, opts = {})
1480
1466
  raise_if_no_longer_open!
1481
1467
 
1482
- exchange_name = if exchange.respond_to?(:name)
1483
- exchange.name
1484
- else
1485
- exchange
1486
- end
1468
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1487
1469
  rk = (opts[:routing_key] || opts[:key])
1488
1470
  args = opts[:arguments]
1489
1471
 
@@ -1499,11 +1481,7 @@ module Bunny
1499
1481
  def queue_bind_without_recording_topology(name, exchange, opts = {})
1500
1482
  raise_if_no_longer_open!
1501
1483
 
1502
- exchange_name = if exchange.respond_to?(:name)
1503
- exchange.name
1504
- else
1505
- exchange
1506
- end
1484
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1507
1485
 
1508
1486
  rk = (opts[:routing_key] || opts[:key])
1509
1487
  args = opts[:arguments]
@@ -1540,11 +1518,7 @@ module Bunny
1540
1518
  def queue_unbind(name, exchange, opts = {})
1541
1519
  raise_if_no_longer_open!
1542
1520
 
1543
- exchange_name = if exchange.respond_to?(:name)
1544
- exchange.name
1545
- else
1546
- exchange
1547
- end
1521
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1548
1522
 
1549
1523
  rk = (opts[:routing_key] || opts[:key])
1550
1524
  args = opts[:arguments]
@@ -1693,16 +1667,8 @@ module Bunny
1693
1667
  def exchange_bind(source, destination, opts = {})
1694
1668
  result = self.exchange_bind_without_recording_topology(source, destination, opts)
1695
1669
 
1696
- source_name = if source.respond_to?(:name)
1697
- source.name
1698
- else
1699
- source
1700
- end
1701
- destination_name = if destination.respond_to?(:name)
1702
- destination.name
1703
- else
1704
- destination
1705
- end
1670
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1671
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1706
1672
  rk = (opts[:routing_key] || opts[:key])
1707
1673
  args = opts[:arguments]
1708
1674
  self.record_exchange_binding_with(self, source_name, destination_name, rk, args)
@@ -1716,17 +1682,9 @@ module Bunny
1716
1682
  def exchange_bind_without_recording_topology(source, destination, opts = {})
1717
1683
  raise_if_no_longer_open!
1718
1684
 
1719
- source_name = if source.respond_to?(:name)
1720
- source.name
1721
- else
1722
- source
1723
- end
1685
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1724
1686
 
1725
- destination_name = if destination.respond_to?(:name)
1726
- destination.name
1727
- else
1728
- destination
1729
- end
1687
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1730
1688
 
1731
1689
  rk = (opts[:routing_key] || opts[:key])
1732
1690
  args = opts[:arguments]
@@ -1764,17 +1722,9 @@ module Bunny
1764
1722
  def exchange_unbind(source, destination, opts = {})
1765
1723
  raise_if_no_longer_open!
1766
1724
 
1767
- source_name = if source.respond_to?(:name)
1768
- source.name
1769
- else
1770
- source
1771
- end
1772
-
1773
- destination_name = if destination.respond_to?(:name)
1774
- destination.name
1775
- else
1776
- destination
1777
- end
1725
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1726
+
1727
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1778
1728
 
1779
1729
  rk = (opts[:routing_key] || opts[:key])
1780
1730
  args = opts[:arguments]
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
- require "monitor"
5
3
  require "amq/int_allocator"
6
4
 
7
5
  module Bunny
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "set"
4
- require "thread"
5
- require "monitor"
6
4
 
7
5
  module Bunny
8
6
  module Concurrent
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
- require "monitor"
5
-
6
3
  module Bunny
7
4
  # @private
8
5
  module Concurrent
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
-
5
3
  module Bunny
6
4
  module Concurrent
7
5
  # Continuation queue implementation for MRI and Rubinius
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
-
5
3
  module Bunny
6
4
  module Concurrent
7
5
  # A thread-safe exception accumulator that stores exceptions for later retrieval
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "set"
4
- require "thread"
5
4
 
6
5
  module Bunny
7
6
  module Concurrent
@@ -111,7 +111,7 @@ module Bunny
111
111
  # @return [String] Name of the queue this consumer is on
112
112
  # @api public
113
113
  def queue_name
114
- if @queue.respond_to?(:name)
114
+ if @queue.is_a?(Bunny::Queue)
115
115
  @queue.name
116
116
  else
117
117
  @queue
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
-
5
3
  module Bunny
6
4
  # Thread pool that dispatches consumer deliveries. Not supposed to be shared between channels
7
5
  # or threads.
@@ -11,21 +11,10 @@ module Bunny
11
11
  module Socket
12
12
  attr_accessor :options
13
13
 
14
- READ_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWaitReadable)
15
- # Ruby 2.1+
16
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable,
17
- IO::EAGAINWaitReadable, IO::EWOULDBLOCKWaitReadable]
18
- else
19
- # 2.0
20
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable]
21
- end
22
- WRITE_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWaitWritable)
23
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable,
24
- IO::EAGAINWaitWritable, IO::EWOULDBLOCKWaitWritable]
25
- else
26
- # 2.0
27
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable]
28
- end
14
+ READ_RETRY_EXCEPTION_CLASSES = [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable,
15
+ IO::EAGAINWaitReadable, IO::EWOULDBLOCKWaitReadable].freeze
16
+ WRITE_RETRY_EXCEPTION_CLASSES = [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable,
17
+ IO::EAGAINWaitWritable, IO::EWOULDBLOCKWaitWritable].freeze
29
18
 
30
19
  def self.open(host, port, options = {})
31
20
  socket = ::Socket.tcp(host, port, nil, nil,
@@ -39,7 +28,7 @@ module Bunny
39
28
  @__bunny_socket_eof_flag__ = false
40
29
  end
41
30
  socket.extend self
42
- socket.options = { :host => host, :port => port }.merge(options)
31
+ socket.options = { host: host, port: port }.merge(options)
43
32
  socket
44
33
  rescue Errno::ETIMEDOUT
45
34
  raise ClientTimeout
@@ -10,21 +10,10 @@ module Bunny
10
10
  # methods found in Bunny::Socket.
11
11
  class SSLSocket < OpenSSL::SSL::SSLSocket
12
12
 
13
- READ_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWaitReadable)
14
- # Ruby 2.1+
15
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable,
16
- IO::EAGAINWaitReadable, IO::EWOULDBLOCKWaitReadable]
17
- else
18
- # 2.0
19
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable]
20
- end
21
- WRITE_RETRY_EXCEPTION_CLASSES = if defined?(IO::EAGAINWaitWritable)
22
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable,
23
- IO::EAGAINWaitWritable, IO::EWOULDBLOCKWaitWritable]
24
- else
25
- # 2.0
26
- [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable]
27
- end
13
+ READ_RETRY_EXCEPTION_CLASSES = [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable,
14
+ IO::EAGAINWaitReadable, IO::EWOULDBLOCKWaitReadable].freeze
15
+ WRITE_RETRY_EXCEPTION_CLASSES = [Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable,
16
+ IO::EAGAINWaitWritable, IO::EWOULDBLOCKWaitWritable].freeze
28
17
 
29
18
  def initialize(*args)
30
19
  super
@@ -52,13 +52,13 @@ module Bunny
52
52
  # @return [Hash] Hash representation of this delivery info
53
53
  def to_hash
54
54
  @hash ||= {
55
- :consumer_tag => @basic_deliver.consumer_tag,
56
- :delivery_tag => @basic_deliver.delivery_tag,
57
- :redelivered => @basic_deliver.redelivered,
58
- :exchange => @basic_deliver.exchange,
59
- :routing_key => @basic_deliver.routing_key,
60
- :consumer => @consumer,
61
- :channel => @channel
55
+ consumer_tag: @basic_deliver.consumer_tag,
56
+ delivery_tag: @basic_deliver.delivery_tag,
57
+ redelivered: @basic_deliver.redelivered,
58
+ exchange: @basic_deliver.exchange,
59
+ routing_key: @basic_deliver.routing_key,
60
+ consumer: @consumer,
61
+ channel: @channel
62
62
  }
63
63
  end
64
64
 
@@ -63,7 +63,7 @@ module Bunny
63
63
  # @example Publishing a messages to the tasks queue
64
64
  # channel = Bunny::Channel.new(connection)
65
65
  # tasks_queue = channel.queue("tasks")
66
- # Bunny::Exchange.default(channel).publish("make clean", :routing_key => "tasks")
66
+ # Bunny::Exchange.default(channel).publish("make clean", routing_key: "tasks")
67
67
  #
68
68
  # @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
69
69
  # @see http://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
@@ -72,7 +72,7 @@ module Bunny
72
72
  # @return [Exchange] An instance that corresponds to the default exchange (of type direct).
73
73
  # @api public
74
74
  def self.default(channel_or_connection)
75
- self.new(channel_or_connection, :direct, AMQ::Protocol::EMPTY_STRING, :no_declare => true)
75
+ self.new(channel_or_connection, :direct, AMQ::Protocol::EMPTY_STRING, no_declare: true)
76
76
  end
77
77
 
78
78
  # @param [Bunny::Channel] channel Channel this exchange will use.
@@ -108,8 +108,9 @@ module Bunny
108
108
 
109
109
  # for basic.return dispatch and such
110
110
  @channel.register_exchange(self)
111
- # for topology recovery
112
- @channel.record_exchange(self)
111
+ # for topology recovery. A passive declaration does not own the exchange,
112
+ # so it must not overwrite what was recorded for it earlier
113
+ @channel.record_exchange(self) unless @options[:passive]
113
114
  end
114
115
 
115
116
  # @return [Boolean] true if this exchange was declared as durable (will survive broker restart).
@@ -271,15 +272,15 @@ module Bunny
271
272
  # @private
272
273
  def self.add_default_options(name, opts)
273
274
  # :nowait is always false for Bunny
274
- h = { :queue => name, :nowait => false }.merge(opts)
275
+ h = { queue: name, nowait: false }.merge(opts)
275
276
 
276
277
  if name.empty?
277
278
  {
278
- :passive => false,
279
- :durable => false,
280
- :auto_delete => false,
281
- :internal => false,
282
- :arguments => nil
279
+ passive: false,
280
+ durable: false,
281
+ auto_delete: false,
282
+ internal: false,
283
+ arguments: nil
283
284
  }.merge(h)
284
285
  else
285
286
  h
data/lib/bunny/framing.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  module Bunny
4
4
  # @private
5
5
  module Framing
6
- ENCODINGS_SUPPORTED = defined? Encoding
7
6
  HEADER_SLICE = (0..6).freeze
8
7
  DATA_SLICE = (7..-1).freeze
9
8
  PAYLOAD_SLICE = (0..-2).freeze
@@ -18,7 +17,7 @@ module Bunny
18
17
  payload = data[PAYLOAD_SLICE]
19
18
  frame_end = data[-1, 1]
20
19
 
21
- frame_end.force_encoding(AMQ::Protocol::Frame::FINAL_OCTET.encoding) if ENCODINGS_SUPPORTED
20
+ frame_end.force_encoding(AMQ::Protocol::Frame::FINAL_OCTET.encoding)
22
21
 
23
22
  # 1) the size is miscalculated
24
23
  if payload.bytesize != size
@@ -47,11 +47,11 @@ module Bunny
47
47
  # @return [Hash] Hash representation of this delivery info
48
48
  def to_hash
49
49
  @hash ||= {
50
- :delivery_tag => @get_ok.delivery_tag,
51
- :redelivered => @get_ok.redelivered,
52
- :exchange => @get_ok.exchange,
53
- :routing_key => @get_ok.routing_key,
54
- :channel => @channel
50
+ delivery_tag: @get_ok.delivery_tag,
51
+ redelivered: @get_ok.redelivered,
52
+ exchange: @get_ok.exchange,
53
+ routing_key: @get_ok.routing_key,
54
+ channel: @channel
55
55
  }
56
56
  end
57
57
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
3
  require "amq/protocol/client"
5
4
  require "amq/protocol/frame"
6
5
 
@@ -31,7 +30,7 @@ module Bunny
31
30
  @interval = [(period / 2) - 1, 0.4].max
32
31
 
33
32
  @thread = Thread.new(&method(:run))
34
- @thread.report_on_exception = false if @thread.respond_to?(:report_on_exception)
33
+ @thread.report_on_exception = false
35
34
  end
36
35
  end
37
36