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.
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/README.md CHANGED
@@ -123,7 +123,9 @@ conn.start
123
123
 
124
124
  # open a channel
125
125
  ch = conn.create_channel
126
- ch.confirm_select
126
+ # enable publisher confirms with automatic tracking,
127
+ # see https://www.rabbitmq.com/docs/publishers#data-safety
128
+ ch.confirm_select(tracking: true)
127
129
 
128
130
  # declare a queue
129
131
  q = ch.queue("test1")
@@ -136,10 +138,6 @@ end
136
138
  # publish a message to the default exchange which then gets routed to this queue
137
139
  q.publish("Hello, everybody!")
138
140
 
139
- # await confirmations from RabbitMQ, see
140
- # https://www.rabbitmq.com/publishers.html#data-safety for details
141
- ch.wait_for_confirms
142
-
143
141
  # give the above consumer some time consume the delivery and print out the message
144
142
  sleep 1
145
143
 
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
@@ -339,6 +337,21 @@ module Bunny
339
337
  @status == :closed
340
338
  end
341
339
 
340
+ # @private
341
+ def connection_closed!
342
+ @status = :closed
343
+ end
344
+
345
+ # @private
346
+ def recovering!
347
+ @status = :recovering
348
+ end
349
+
350
+ # @private
351
+ def recovery_completed!
352
+ @status = :open
353
+ end
354
+
342
355
  #
343
356
  # @group Backwards compatibility with 0.8.0
344
357
  #
@@ -506,7 +519,7 @@ module Bunny
506
519
  # @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
507
520
  # @api public
508
521
  def queue(name = AMQ::Protocol::EMPTY_STRING, opts = {})
509
- throw ArgumentError.new("queue name must not be nil") if name.nil?
522
+ raise ArgumentError, "queue name must not be nil" if name.nil?
510
523
 
511
524
  q = find_queue(name) || Bunny::Queue.new(self, name, opts)
512
525
 
@@ -526,8 +539,8 @@ module Bunny
526
539
  # @see #queue
527
540
  # @api public
528
541
  def quorum_queue(name, opts = {})
529
- throw ArgumentError.new("quorum queue name must not be nil") if name.nil?
530
- 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?
531
544
 
532
545
  durable_queue(name, Bunny::Queue::Types::QUORUM, opts)
533
546
  end
@@ -548,8 +561,8 @@ module Bunny
548
561
  # @see #queue
549
562
  # @api public
550
563
  def stream(name, opts = {})
551
- throw ArgumentError.new("stream name must not be nil") if name.nil?
552
- 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?
553
566
 
554
567
  durable_queue(name, Bunny::Queue::Types::STREAM, opts)
555
568
  end
@@ -570,15 +583,15 @@ module Bunny
570
583
  # @see #queue
571
584
  # @api public
572
585
  def delayed_queue(name, opts = {})
573
- throw ArgumentError.new("delayed queue name must not be nil") if name.nil?
574
- 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?
575
588
 
576
589
  args = opts[:arguments] || {}
577
590
  args[Bunny::Queue::XArgs::DELAYED_RETRY_TYPE] = opts[:delayed_retry_type] if opts[:delayed_retry_type]
578
591
  args[Bunny::Queue::XArgs::DELAYED_RETRY_MIN] = opts[:delayed_retry_min] if opts[:delayed_retry_min]
579
592
  args[Bunny::Queue::XArgs::DELAYED_RETRY_MAX] = opts[:delayed_retry_max] if opts[:delayed_retry_max]
580
593
 
581
- final_opts = opts.merge(:arguments => args)
594
+ final_opts = opts.merge(arguments: args)
582
595
  final_opts.delete(:delayed_retry_type)
583
596
  final_opts.delete(:delayed_retry_min)
584
597
  final_opts.delete(:delayed_retry_max)
@@ -601,14 +614,14 @@ module Bunny
601
614
  # @see #queue
602
615
  # @api public
603
616
  def jms_queue(name, opts = {})
604
- throw ArgumentError.new("JMS queue name must not be nil") if name.nil?
605
- 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?
606
619
 
607
620
  args = opts[:arguments] || {}
608
621
  args[Bunny::Queue::XArgs::SELECTOR_FIELDS] = opts[:selector_fields] if opts[:selector_fields]
609
622
  args[Bunny::Queue::XArgs::SELECTOR_FIELD_MAX_BYTES] = opts[:selector_field_max_bytes] if opts[:selector_field_max_bytes]
610
623
 
611
- final_opts = opts.merge(:arguments => args)
624
+ final_opts = opts.merge(arguments: args)
612
625
  final_opts.delete(:selector_fields)
613
626
  final_opts.delete(:selector_field_max_bytes)
614
627
 
@@ -627,16 +640,16 @@ module Bunny
627
640
  # @see #queue
628
641
  # @api public
629
642
  def durable_queue(name, type = "classic", opts = {})
630
- throw ArgumentError.new("queue name must not be nil") if name.nil?
631
- 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?
632
645
 
633
- final_opts = opts.merge({
634
- :type => type,
635
- :durable => true,
646
+ final_opts = opts.merge(
647
+ type: type,
648
+ durable: true,
636
649
  # exclusive or auto-delete QQs do not make much sense
637
- :exclusive => false,
638
- :auto_delete => false
639
- })
650
+ exclusive: false,
651
+ auto_delete: false
652
+ )
640
653
  q = find_queue(name) || Bunny::Queue.new(self, name, final_opts)
641
654
 
642
655
  record_queue(q)
@@ -651,7 +664,7 @@ module Bunny
651
664
  # @api public
652
665
  def temporary_queue(opts = {})
653
666
  temporary_queue_opts = {
654
- :exclusive => true
667
+ exclusive: true
655
668
  }
656
669
  queue("", opts.merge(temporary_queue_opts))
657
670
  end
@@ -758,11 +771,7 @@ module Bunny
758
771
  raise_if_no_longer_open!
759
772
  raise ArgumentError, "routing key cannot be longer than #{SHORTSTR_LIMIT} characters" if routing_key && routing_key.size > SHORTSTR_LIMIT
760
773
 
761
- exchange_name = if exchange.respond_to?(:name)
762
- exchange.name
763
- else
764
- exchange
765
- end
774
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
766
775
 
767
776
  mode = if opts.fetch(:persistent, true)
768
777
  2
@@ -833,11 +842,7 @@ module Bunny
833
842
  raise ArgumentError, "routing key cannot be longer than #{SHORTSTR_LIMIT} characters" if routing_key && routing_key.size > SHORTSTR_LIMIT
834
843
  return self if payloads.empty?
835
844
 
836
- exchange_name = if exchange.respond_to?(:name)
837
- exchange.name
838
- else
839
- exchange
840
- end
845
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
841
846
 
842
847
  mode = opts.fetch(:persistent, true) ? 2 : 1
843
848
  opts = opts.dup
@@ -907,12 +912,12 @@ module Bunny
907
912
  # conn.start
908
913
  # ch = conn.create_channel
909
914
  # # here we assume the queue already exists and has messages
910
- # 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)
911
916
  # ch.acknowledge(delivery_info.delivery_tag)
912
917
  # @see Bunny::Queue#pop
913
918
  # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
914
919
  # @api public
915
- def basic_get(queue, opts = {:manual_ack => true})
920
+ def basic_get(queue, opts = { manual_ack: true })
916
921
  raise_if_no_longer_open!
917
922
 
918
923
  unless opts[:ack].nil?
@@ -1031,7 +1036,7 @@ module Bunny
1031
1036
  #
1032
1037
  # ch = conn.create_channel
1033
1038
  # # we assume the queue exists and has messages
1034
- # 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)
1035
1040
  # ch.basic_reject(delivery_info.delivery_tag, true)
1036
1041
  #
1037
1042
  # @see Bunny::Channel#basic_nack
@@ -1066,7 +1071,7 @@ module Bunny
1066
1071
  #
1067
1072
  # ch = conn.create_channel
1068
1073
  # # we assume the queue exists and has messages
1069
- # 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)
1070
1075
  # ch.basic_ack(delivery_info.delivery_tag.to_i)
1071
1076
  #
1072
1077
  # @example Ack multiple messages fetched via basic.get
@@ -1075,9 +1080,9 @@ module Bunny
1075
1080
  #
1076
1081
  # ch = conn.create_channel
1077
1082
  # # we assume the queue exists and has messages
1078
- # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1079
- # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1080
- # 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)
1081
1086
  # # ack all fetched messages up to payload3
1082
1087
  # ch.basic_ack(delivery_info.delivery_tag.to_i, true)
1083
1088
  #
@@ -1126,7 +1131,7 @@ module Bunny
1126
1131
  #
1127
1132
  # ch = conn.create_channel
1128
1133
  # # we assume the queue exists and has messages
1129
- # 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)
1130
1135
  # ch.basic_nack(delivery_info.delivery_tag, false, true)
1131
1136
  #
1132
1137
  #
@@ -1136,9 +1141,9 @@ module Bunny
1136
1141
  #
1137
1142
  # ch = conn.create_channel
1138
1143
  # # we assume the queue exists and has messages
1139
- # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1140
- # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true)
1141
- # 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)
1142
1147
  # # requeue all fetched messages up to payload3
1143
1148
  # ch.basic_nack(delivery_info.delivery_tag, true, true)
1144
1149
  #
@@ -1174,11 +1179,7 @@ module Bunny
1174
1179
  raise_if_no_longer_open!
1175
1180
  maybe_start_consumer_work_pool!
1176
1181
 
1177
- queue_name = if queue.respond_to?(:name)
1178
- queue.name
1179
- else
1180
- queue
1181
- end
1182
+ queue_name = queue.is_a?(Bunny::Queue) ? queue.name : queue
1182
1183
 
1183
1184
  # helps avoid race condition between basic.consume-ok and basic.deliver if there are messages
1184
1185
  # in the queue already. MK.
@@ -1464,11 +1465,7 @@ module Bunny
1464
1465
  def queue_bind(name, exchange, opts = {})
1465
1466
  raise_if_no_longer_open!
1466
1467
 
1467
- exchange_name = if exchange.respond_to?(:name)
1468
- exchange.name
1469
- else
1470
- exchange
1471
- end
1468
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1472
1469
  rk = (opts[:routing_key] || opts[:key])
1473
1470
  args = opts[:arguments]
1474
1471
 
@@ -1484,11 +1481,7 @@ module Bunny
1484
1481
  def queue_bind_without_recording_topology(name, exchange, opts = {})
1485
1482
  raise_if_no_longer_open!
1486
1483
 
1487
- exchange_name = if exchange.respond_to?(:name)
1488
- exchange.name
1489
- else
1490
- exchange
1491
- end
1484
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1492
1485
 
1493
1486
  rk = (opts[:routing_key] || opts[:key])
1494
1487
  args = opts[:arguments]
@@ -1525,11 +1518,7 @@ module Bunny
1525
1518
  def queue_unbind(name, exchange, opts = {})
1526
1519
  raise_if_no_longer_open!
1527
1520
 
1528
- exchange_name = if exchange.respond_to?(:name)
1529
- exchange.name
1530
- else
1531
- exchange
1532
- end
1521
+ exchange_name = exchange.is_a?(Bunny::Exchange) ? exchange.name : exchange
1533
1522
 
1534
1523
  rk = (opts[:routing_key] || opts[:key])
1535
1524
  args = opts[:arguments]
@@ -1678,16 +1667,8 @@ module Bunny
1678
1667
  def exchange_bind(source, destination, opts = {})
1679
1668
  result = self.exchange_bind_without_recording_topology(source, destination, opts)
1680
1669
 
1681
- source_name = if source.respond_to?(:name)
1682
- source.name
1683
- else
1684
- source
1685
- end
1686
- destination_name = if destination.respond_to?(:name)
1687
- destination.name
1688
- else
1689
- destination
1690
- end
1670
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1671
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1691
1672
  rk = (opts[:routing_key] || opts[:key])
1692
1673
  args = opts[:arguments]
1693
1674
  self.record_exchange_binding_with(self, source_name, destination_name, rk, args)
@@ -1701,17 +1682,9 @@ module Bunny
1701
1682
  def exchange_bind_without_recording_topology(source, destination, opts = {})
1702
1683
  raise_if_no_longer_open!
1703
1684
 
1704
- source_name = if source.respond_to?(:name)
1705
- source.name
1706
- else
1707
- source
1708
- end
1685
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1709
1686
 
1710
- destination_name = if destination.respond_to?(:name)
1711
- destination.name
1712
- else
1713
- destination
1714
- end
1687
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1715
1688
 
1716
1689
  rk = (opts[:routing_key] || opts[:key])
1717
1690
  args = opts[:arguments]
@@ -1749,17 +1722,9 @@ module Bunny
1749
1722
  def exchange_unbind(source, destination, opts = {})
1750
1723
  raise_if_no_longer_open!
1751
1724
 
1752
- source_name = if source.respond_to?(:name)
1753
- source.name
1754
- else
1755
- source
1756
- end
1725
+ source_name = source.is_a?(Bunny::Exchange) ? source.name : source
1757
1726
 
1758
- destination_name = if destination.respond_to?(:name)
1759
- destination.name
1760
- else
1761
- destination
1762
- end
1727
+ destination_name = destination.is_a?(Bunny::Exchange) ? destination.name : destination
1763
1728
 
1764
1729
  rk = (opts[:routing_key] || opts[:key])
1765
1730
  args = opts[:arguments]
@@ -2250,7 +2215,9 @@ module Bunny
2250
2215
 
2251
2216
  # basic.ack, basic.reject, basic.nack. MK.
2252
2217
  if channel_level_exception_after_operation_that_has_no_response?(method)
2253
- @on_error.call(self, method) if @on_error
2218
+ # Runs outside the reader loop so that the callback can perform
2219
+ # blocking operations such as channel.reopen.
2220
+ Thread.new { @on_error.call(self, method) } if @on_error
2254
2221
  else
2255
2222
  @last_channel_error = instantiate_channel_level_exception(method)
2256
2223
  @continuations.push(method)
@@ -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.
@@ -271,15 +271,15 @@ module Bunny
271
271
  # @private
272
272
  def self.add_default_options(name, opts)
273
273
  # :nowait is always false for Bunny
274
- h = { :queue => name, :nowait => false }.merge(opts)
274
+ h = { queue: name, nowait: false }.merge(opts)
275
275
 
276
276
  if name.empty?
277
277
  {
278
- :passive => false,
279
- :durable => false,
280
- :auto_delete => false,
281
- :internal => false,
282
- :arguments => nil
278
+ passive: false,
279
+ durable: false,
280
+ auto_delete: false,
281
+ internal: false,
282
+ arguments: nil
283
283
  }.merge(h)
284
284
  else
285
285
  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