march_hare 4.6.0-java → 4.7.0-java

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
  SHA256:
3
- metadata.gz: 9f3076067130e44a2c49fc4789b38d15b18ab7c4ca01ad19cc5d9c45d0ac0242
4
- data.tar.gz: 8cbdeb88ff5e273620158933104deab45a450afd1ef2cc193e6e48b7661ce4b3
3
+ metadata.gz: dbcc08d76c936d48219df49aeb1e42b7495d20151ff4acea5441bb3bcd4834c0
4
+ data.tar.gz: 1a49f5a57d3d118ef6d099ac35a181199afb300458a67fe8f6b47cb1e7c8e394
5
5
  SHA512:
6
- metadata.gz: 2f2e7d323e3e212bc51c98df47ce6311dfa2f0e47eac07ba75dd229a5ed20be2af590cbf356f2547fe9ec6a8f682c6e0d6101cd0f6503863cb2b5a9e2d81a5a1
7
- data.tar.gz: a432d8e6ef0d5d2df4cc552edaa4a4215e9dfe62b99bf4eb0f30a56b5fb59db4619cf5fe829a7ec1507d490f7140e0d79737d5f1b25f23acde1c11f9a2905e23
6
+ metadata.gz: 52c1ca909abfe296dc53ed64ff4da122a93bdec28ee141a190317cd5681ef9c8db2a2170fa0cfc97077012766f0cd9eefcb9318750dbe6259f89eea320217201
7
+ data.tar.gz: adefc87af6121d7e7c4fdec9d49fdbeb62aaf0a4ac4247b9d86c704b83822b8714baca7bb9a5ddec79ac37c862505bd94243f4b08e21682c84265a6cbde8da26
Binary file
@@ -132,6 +132,11 @@ module MarchHare
132
132
  @confirm_hooks = Array.new
133
133
  @recoveries_counter = JavaConcurrent::AtomicInteger.new(0)
134
134
 
135
+ # An opt-in setting that instructs the channel to cancel all consumers
136
+ # before closing. This helps reduce the probability of in-flight deliveries
137
+ # right before channel closure.
138
+ @cancel_consumers_before_closing = false
139
+
135
140
  on_shutdown do |ch, cause|
136
141
  ch.gracefully_shut_down_consumers
137
142
  end
@@ -161,12 +166,33 @@ module MarchHare
161
166
  @delegate.open?
162
167
  end
163
168
 
169
+ def closed?
170
+ !open?
171
+ end
172
+
164
173
  # Closes the channel.
165
174
  #
166
175
  # Closed channels can no longer be used. Closed channel id is
167
176
  # returned back to the pool of available ids and may be used by
168
177
  # a different channel opened later.
169
178
  def close(code = 200, reason = "Goodbye")
179
+ # This is a best-effort attempt to cancel all consumers before closing the channel.
180
+ # Retries are extremely unlikely to succeed, and the channel itself is about to be closed,
181
+ # so we don't bother retrying.
182
+ if self.cancel_consumers_before_closing?
183
+ # cancelling a consumer involves using the same mutex, so avoid holding the lock
184
+ keys = @consumers.keys
185
+ keys.each do |ctag|
186
+ begin
187
+ self.basic_cancel(ctag)
188
+ rescue Bunny::Exception
189
+ # ignore
190
+ rescue Bunny::ClientTimeout
191
+ # ignore
192
+ end
193
+ end
194
+ end
195
+
170
196
  v = @delegate.close(code, reason)
171
197
 
172
198
  @consumers.each do |tag, consumer|
@@ -178,6 +204,21 @@ module MarchHare
178
204
  v
179
205
  end
180
206
 
207
+
208
+ def configure(&block)
209
+ block.call(self) if block_given?
210
+
211
+ self
212
+ end
213
+
214
+ def cancel_consumers_before_closing!
215
+ @cancel_consumers_before_closing = true
216
+ end
217
+
218
+ def cancel_consumers_before_closing?
219
+ !!@cancel_consumers_before_closing
220
+ end
221
+
181
222
  # Defines a shutdown event callback. Shutdown events are
182
223
  # broadcasted when a channel is closed, either explicitly
183
224
  # or forcefully, or due to a network/peer failure.
@@ -482,7 +523,7 @@ module MarchHare
482
523
  # @return [MarchHare::Queue] Queue that was declared or looked up in the cache
483
524
  # @see http://rubymarchhare.info/articles/queues.html Queues and Consumers guide
484
525
  # @see http://rubymarchhare.info/articles/extensions.html RabbitMQ Extensions guide
485
- def queue(name, options={})
526
+ def queue(name, options = {})
486
527
  dq = Queue.new(self, name, options).tap do |q|
487
528
  q.declare!
488
529
  end
@@ -490,6 +531,85 @@ module MarchHare
490
531
  self.register_queue(dq)
491
532
  end
492
533
 
534
+ # Declares a new client-named quorum queue.
535
+ #
536
+ # @param [String] name Queue name. Empty (server-generated) names are not supported by this method.
537
+ # @param [Hash] opts Queue properties and other options. Durability, exclusivity, auto-deletion options will be ignored.
538
+ #
539
+ # @option opts [Hash] :arguments ({}) Optional arguments (x-arguments)
540
+ #
541
+ # @return [MarchHare::Queue] Queue that was declared or looked up in the cache
542
+ # @see #durable_queue
543
+ # @see #queue
544
+ # @api public
545
+ def quorum_queue(name, opts = {})
546
+ throw ArgumentError.new("quorum queue name must not be nil") if name.nil?
547
+ throw ArgumentError.new("quorum queue name must not be empty (server-named QQs do not make sense)") if name.empty?
548
+
549
+ durable_queue(name, Queue::Types::QUORUM, opts)
550
+ end
551
+
552
+ # Declares a new client-named stream (that Bunny can use as if it was a queue).
553
+ # Note that Bunny would still use AMQP 0-9-1 to perform operations on this "queue".
554
+ # To use stream-specific operations and to gain from stream protocol efficiency and partitioning,
555
+ # use a Ruby client for the RabbitMQ stream protocol.
556
+ #
557
+ # @param [String] name Stream name. Empty (server-generated) names are not supported by this method.
558
+ # @param [Hash] opts Queue properties and other options. Durability, exclusivity, auto-deletion options will be ignored.
559
+ #
560
+ # @option opts [Hash] :arguments ({}) Optional arguments (x-arguments)
561
+ #
562
+ #
563
+ # @return [MarchHare::Queue] Queue that was declared or looked up in the cache
564
+ # @see #durable_queue
565
+ # @see #queue
566
+ # @api public
567
+ def stream(name, opts = {})
568
+ throw ArgumentError.new("stream name must not be nil") if name.nil?
569
+ throw ArgumentError.new("stream name must not be empty (server-named QQs do not make sense)") if name.empty?
570
+
571
+ durable_queue(name, Queue::Types::STREAM, opts)
572
+ end
573
+
574
+ # Declares a new server-named queue that is automatically deleted when the
575
+ # connection is closed.
576
+ #
577
+ # @param [String] name Queue name. Empty (server-generated) names are not supported by this method.
578
+ # @param [Hash] opts Queue properties and other options. Durability, exclusivity, auto-deletion options will be ignored.
579
+ #
580
+ # @option opts [Hash] :arguments ({}) Optional arguments (x-arguments)
581
+ #
582
+ # @return [MarchHare::Queue] Queue that was declared or looked up in the cache
583
+ # @see #queue
584
+ # @api public
585
+ def durable_queue(name, type = Queue::Types::CLASSIC, opts = {})
586
+ throw ArgumentError.new("queue name must not be nil") if name.nil?
587
+ throw ArgumentError.new("queue name must not be empty (server-named durable queues do not make sense)") if name.empty?
588
+
589
+ final_opts = opts.merge({
590
+ :type => type,
591
+ :durable => true,
592
+ # exclusive or auto-delete QQs do not make much sense
593
+ :exclusive => false,
594
+ :auto_delete => false
595
+ })
596
+
597
+ self.queue(name, final_opts)
598
+ end
599
+
600
+ # Declares a new server-named queue that is automatically deleted when the
601
+ # connection is closed.
602
+ #
603
+ # @return [MarchHare::Queue] Queue that was declared or looked up in the cache
604
+ # @see #queue
605
+ # @api public
606
+ def temporary_queue(opts = {})
607
+ temporary_queue_opts = {
608
+ :exclusive => true
609
+ }
610
+ queue("", opts.merge(temporary_queue_opts))
611
+ end
612
+
493
613
  # Declares a queue using queue.declare AMQP 0.9.1 method.
494
614
  #
495
615
  # @param [String] name Queue name
@@ -638,6 +758,13 @@ module MarchHare
638
758
  tag
639
759
  end
640
760
 
761
+ def basic_cancel(consumer_tag)
762
+ converting_rjc_exceptions_to_ruby do
763
+ @delegate.basic_cancel(consumer_tag)
764
+ end
765
+ self.unregister_consumer(consumer_tag)
766
+ end
767
+
641
768
  def basic_qos(prefetch_count)
642
769
  r = converting_rjc_exceptions_to_ruby do
643
770
  @delegate.basic_qos(prefetch_count)
@@ -11,6 +11,27 @@ module MarchHare
11
11
  # @see http://rubymarchhare.info/articles/queues.html Queues and Consumers guide
12
12
  # @see http://rubymarchhare.info/articles/extensions.html RabbitMQ Extensions guide
13
13
  class Queue
14
+ #
15
+ # API
16
+ #
17
+
18
+ module Types
19
+ QUORUM = "quorum"
20
+ CLASSIC = "classic"
21
+ STREAM = "stream"
22
+
23
+ KNOWN = [CLASSIC, QUORUM, STREAM]
24
+
25
+ def self.known?(q_type)
26
+ KNOWN.include?(q_type)
27
+ end
28
+ end
29
+
30
+ module XArgs
31
+ MAX_LENGTH = "x-max-length",
32
+ QUEUE_TYPE = "x-queue-type"
33
+ end
34
+
14
35
  # @return [MarchHare::Channel] Channel this queue uses
15
36
  attr_reader :channel
16
37
  # @return [String] Queue name
@@ -33,13 +54,20 @@ module MarchHare
33
54
 
34
55
  @channel = channel
35
56
  @name = name
36
- @options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new}.merge(options)
57
+ @options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new, :type => Types::CLASSIC}.merge(options)
37
58
 
59
+ @type = @options[:type].to_s
38
60
  @durable = @options[:durable]
39
61
  @exclusive = @options[:exclusive]
40
62
  @server_named = @name.empty?
41
63
  @auto_delete = @options[:auto_delete]
42
- @arguments = @options[:arguments]
64
+
65
+ @arguments = if @type and !@type.empty? then
66
+ (@options[:arguments] || {}).merge({XArgs::QUEUE_TYPE => @type})
67
+ else
68
+ @options[:arguments]
69
+ end
70
+ verify_type!(@arguments)
43
71
 
44
72
  @bindings = Set.new
45
73
  end
@@ -74,8 +102,6 @@ module MarchHare
74
102
  @arguments
75
103
  end
76
104
 
77
-
78
-
79
105
  # Binds queue to an exchange
80
106
  #
81
107
  # @param [MarchHare::Exchange,String] exchange Exchange to bind to
@@ -225,6 +251,18 @@ module MarchHare
225
251
  # Implementation
226
252
  #
227
253
 
254
+ def self.verify_type!(args0 = {})
255
+ # be extra defensive
256
+ args = args0 || {}
257
+ q_type = args["x-queue-type"] || args[:"x-queue-type"]
258
+ throw ArgumentError.new(
259
+ "unsupported queue type #{q_type.inspect}, supported ones: #{Types::KNOWN.join(', ')}") if (q_type and !Types.known?(q_type))
260
+ end
261
+
262
+ def verify_type!(args)
263
+ self.class.verify_type!(args)
264
+ end
265
+
228
266
  # @return [Boolean] true if this queue is a pre-defined one (amq.direct, amq.fanout, amq.match and so on)
229
267
  def predefined?
230
268
  @name.start_with?("amq.")
@@ -232,10 +270,10 @@ module MarchHare
232
270
 
233
271
  # @private
234
272
  def declare!
235
- @channel.logger.debug("queue: declare! #{@name}")
273
+ @channel.logger.debug("queue: declare! #{@name}, type: #{@type}")
236
274
  response = if @options[:passive]
237
275
  then @channel.queue_declare_passive(@name)
238
- else @channel.queue_declare(@name, @options[:durable], @options[:exclusive], @options[:auto_delete], @options[:arguments])
276
+ else @channel.queue_declare(@name, @durable, @exclusive, @auto_delete, @arguments)
239
277
  end
240
278
  @name = response.queue
241
279
  end
@@ -57,6 +57,7 @@ module MarchHare
57
57
  # @option options [Logger] :logger The logger. If missing, one is created using :log_file and :log_level.
58
58
  # @option options [IO, String] :log_file The file or path to use when creating a logger. Defaults to STDOUT.
59
59
  # @option options [Integer] :log_level The log level to use when creating a logger. Defaults to LOGGER::WARN
60
+ # @option options [Integer] :max_inbound_message_body_size Maximum allowed size of an incoming message body. Defaults to 64MiB
60
61
  #
61
62
  # @see http://rubymarchhare.info/articles/connecting.html Connecting to RabbitMQ guide
62
63
  def self.connect(options = {})
@@ -83,6 +84,8 @@ module MarchHare
83
84
 
84
85
  cf.thread_factory = thread_factory_from(options) if include_thread_factory?(options)
85
86
 
87
+ cf.max_inbound_message_body_size = options[:max_inbound_message_body_size].to_i if options[:max_inbound_message_body_size]
88
+
86
89
  tls = (options[:ssl] || options[:tls])
87
90
  case tls
88
91
  when true then
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module MarchHare
4
- VERSION = "4.6.0"
4
+ VERSION = "4.7.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: march_hare
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.0
4
+ version: 4.7.0
5
5
  platform: java
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  - Michael S. Klishin
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-11-10 00:00:00.000000000 Z
11
+ date: 2025-03-24 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: RabbitMQ client for JRuby built around the official RabbitMQ Java client
15
14
  email:
@@ -41,7 +40,6 @@ files:
41
40
  homepage: https://github.com/ruby-amqp/march_hare
42
41
  licenses: []
43
42
  metadata: {}
44
- post_install_message:
45
43
  rdoc_options: []
46
44
  require_paths:
47
45
  - lib
@@ -56,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
54
  - !ruby/object:Gem::Version
57
55
  version: '0'
58
56
  requirements: []
59
- rubygems_version: 3.3.26
60
- signing_key:
57
+ rubygems_version: 3.6.3
61
58
  specification_version: 4
62
59
  summary: RabbitMQ client for JRuby built around the official RabbitMQ Java client
63
60
  test_files: []