Skip to content

Ruby 3.0 modernisation, code quality improvements, and gem cleanup#735

Merged
michaelklishin merged 9 commits into
ruby-amqp:mainfrom
eglitobias:modernize-for-ruby-3
Apr 23, 2026
Merged

Ruby 3.0 modernisation, code quality improvements, and gem cleanup#735
michaelklishin merged 9 commits into
ruby-amqp:mainfrom
eglitobias:modernize-for-ruby-3

Conversation

@eglitobias
Copy link
Copy Markdown
Contributor

Motivation

These messaging gems are critical dependencies in our production app, so I've been investing time in modernising the RabbitMQ Ruby ecosystem (hutch, amq-protocol) and want to contribute similar cleanup to Bunny. This PR removes accumulated legacy code and tightens things up for the Ruby 3.0+ baseline Bunny already requires.

Changes

Ruby 3.0 modernisation

  • Remove Ruby 2.0/2.1 compatibility guards (defined? Encoding, respond_to?(:report_on_exception), encoding magic comments, require "thread", require "monitor")
  • Sweep the remaining :key => hash rocket syntax in lib/ over to key:

Bug fix

  • Several queue helpers (quorum_queue, stream, durable_queue, delayed_queue, jms_queue, queue) used throw ArgumentError.new(...) to signal validation errors. With no matching catch, this raises UncaughtThrowError instead of ArgumentError. Switched to raise ArgumentError, "..." and updated the specs that asserted the wrong error class

Code quality

  • Deduplicate @channels[ch_number] hash lookup in handle_frameset — single lookup per frame instead of two
  • Replace respond_to?(:name) duck-type checks with is_a?(Bunny::Exchange) / is_a?(Bunny::Queue) in the publish, bind, and consumer hot paths

Gem / Gemfile cleanup

  • Remove redundant shebang and encoding comments from gemspec and Gemfile
  • Remove duplicate vendor block from Gemfile
  • Pin amq-protocol to ~> 2.7 to match the runtime dependency

Several queue helper methods (quorum_queue, stream, durable_queue,
delayed_queue, jms_queue, queue) used `throw ArgumentError.new(...)`
to signal validation errors. With no matching `catch` block, Ruby
raises `UncaughtThrowError` rather than `ArgumentError`, which is
neither the documented nor intended behavior.

Switch these call sites to `raise ArgumentError, "..."` and update
the existing specs that asserted `UncaughtThrowError` to expect
`ArgumentError` instead.
Sweep the remaining `:key =>` hash rocket syntax in lib/ over to the
modern `key:` form. Covers default option hashes, merge calls,
DEFAULT_CLIENT_PROPERTIES, return/delivery/get_response to_hash
outputs, and docstring examples.

Also drop the redundant `# encoding: utf-8` magic comment from
version.rb (UTF-8 is the default source encoding since Ruby 2.0).
@michaelklishin michaelklishin merged commit bd69cba into ruby-amqp:main Apr 23, 2026
24 of 29 checks passed
@michaelklishin
Copy link
Copy Markdown
Member

The failures are connection recovery flakes. I will get to them eventually.

@michaelklishin michaelklishin added this to the 3.2.0 milestone Apr 23, 2026
michaelklishin added a commit that referenced this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants