Releases: cloudamqp/amqp-client.rb
Release 2.0.0
We're excited to announce the release of AMQP Client 2.0! This major version brings significant improvements to API clarity, consistency, and functionality while introducing powerful new features for automatic message encoding and configuration management.
π― Highlights
- Keyword Arguments Throughout - All public methods now use keyword arguments for improved clarity and safety
- Unified Configuration API - New
AMQP::Client.configureblock for centralized configuration - Automatic Message Encoding - Built-in support for JSON, gzip, and deflate with extensible codec registry
- RPC Support - Native RPC client/server implementation
- Enhanced Consumer Control - Subscribe methods now return cancelable
Consumerobjects - Automatic Ack/Reject -
Queue#subscribehandles acknowledgments automatically
π Breaking Changes
1. Keyword Arguments (All APIs)
All public methods now require keyword arguments instead of positional arguments:
# v1.x
amqp.publish("message", "amq.topic", "routing.key")
# v2.0
amqp.publish("message", exchange: "amq.topic", routing_key: "routing.key")Migration: Update all method calls to use keyword arguments. See the Migration Guide for complete examples.
2. Exchange Convenience Methods Renamed
Exchange type methods now have an _exchange suffix for clarity:
# v1.x
amqp.direct()
amqp.topic()
amqp.fanout()
# v2.0
amqp.direct_exchange()
amqp.topic_exchange()
amqp.fanout_exchange()3. Direct Exchange Default Name
The default direct exchange name changed from "" to "amq.direct" for consistency:
# v1.x
amqp.direct() # Returns exchange with name ""
# v2.0
amqp.direct_exchange() # Returns "amq.direct"
amqp.direct_exchange("") # Explicitly use empty string if needed4. Subscribe Returns Consumer
Client#subscribe and Queue#subscribe now return a Consumer object that can be cancelled:
consumer = queue.subscribe(prefetch: 10) do |msg|
# Process message
end
# Later...
consumer.cancel5. Other Breaking Changes
Channel#basic_subscribenow returnsConnection::Channel::ConsumeOkConnection::Channel::QueueOkis now an immutableDataclass instead ofStruct
β¨ New Features
Unified Configuration
Configure all settings in one place with the new configure block:
AMQP::Client.configure do |config|
config.enable_builtin_codecs # JSON, gzip, deflate
config.default_content_type = "application/json"
config.default_content_encoding = "gzip"
config.strict_coding = true
# Register custom codecs
config.register_parser(content_type: "application/msgpack", parser: MsgPackParser)
endAutomatic Message Encoding
Built-in support for JSON serialization and compression:
# Enable built-in codecs
AMQP::Client.configure do |config|
config.enable_builtin_codecs
end
# Automatically serializes to JSON
queue.publish({ user: "john", action: "login" }, content_type: "application/json")
# Automatically deserializes
queue.subscribe do |msg|
data = msg.parse # Returns Ruby hash
endSupported formats:
application/json- JSON encoding/decodinggzip- Gzip compressiondeflate- Deflate compression
Automatic Ack/Reject
Queue#subscribe now handles message acknowledgments automatically:
queue.subscribe(prefetch: 20) do |msg|
process(msg)
# Automatically ack'd on success
# Automatically rejected (with requeue) on exception
endManual control is still available if needed.
RPC Support
Native RPC implementation for request-response patterns:
# Server
amqp.rpc_server("rpc_queue") do |request|
{ result: request[:value] * 2 }
end
# Client
rpc = amqp.rpc_client
response = rpc.call({ value: 21 }, routing_key: "rpc_queue")
# => { result: 42 }Queue Polling
Poll messages without subscribing:
msg = queue.get
if msg
process(msg)
msg.ack
endEnhanced Queue Options
passive- Check queue existence without creatingexclusive- Delete queue when connection closes
Improved Consumer Management
Client#started?- Check if client is startedMessage#delivery_info- Structured access to delivery metadata- Consumer objects can be cancelled
π§ Additional Improvements
- Thread Safety -
Client#startis now thread-safe - Confirm Handling -
wait_for_confirmsproperly handles NACKs and returns boolean - Network Optimization - Nagle's algorithm disabled for lower latency
- Bug Fixes - Various fixes including minitest compatibility
π Migration
Please review the complete Migration Guide for detailed migration instructions, code examples, and a step-by-step checklist.
Quick Migration Checklist
- β Update all method calls to use keyword arguments
- β
Rename
direct(),fanout(),topic(),headers()to*_exchange() - β
Replace
require "amqp-client/enable_builtin_codecs"with configure block - β
Store returned
Consumerobjects if you need to cancel subscriptions - β Review direct exchange usage if relying on empty string default
- β
Update any code mutating
QueueOkstructures
Migration Support
- π Full Migration Guide
- π API Documentation
- π¬ Open an Issue
- π§ Contact Support
π Acknowledgments
Thank you to everyone who contributed feedback, bug reports, and suggestions that shaped this release!
Full Changelog: v1.2.1...v2.0.0
Release 1.2.1
- Added: Convenience methods for creating exchange types:
fanout(),direct(),topic(), andheaders() - Added: Support for binding with high level objects (Exchange and Queue objects can now be passed as binding sources)
- Fixed: Bug where a client without any connection could not be closed properly
v1.2.0
What's Changed
- Bugfix: thread safe channel creation by @spuun in #32
- Heartbeat support by @carlhoerberg in #35
- CI: Don't try to run RuboCop on Ruby 2.6 by @dentarg in #38
- CI: JRuby doesn't like
localhostby @dentarg in #39 - CI: Use TruffleRuby 24.2.2 in TLS tests by @dentarg in #40
- Raise the required Ruby version to Ruby 3.2 by @dentarg in #41
- Full heartbeat support by @baelter in #36
Full Changelog: v1.1.7...v1.2.0