Very low-level AMQP 0.9.1 client which is supposed to be used for implementing more high-level AMQP libraries rather than to be used by the end users.
The Overall AMQP Gems Architecture
|--------------| |-----------------------| |-------------------| | AMQ-Protocol | | AMQ-Client | | AMQP gem & others | | - Encoding | ===> | - IO abstraction | ===> | - high-level API | | - Decoding | | - Low-level AMQP API | | - opinionated | | - Framing | |-----------------------| |-------------------| |--------------|
So the most low-level part is the AMQ-Protocol gem. Its only job is to take care about encoding, decoding and framing. Reasons for having it as a standalone gem is that it’ll be easy to replace the current implementation by a different one which can be a rewrite for another AMQP version or just an optimised version written in C.
The next piece in the puzzle is AMQ-Client gem which takes care about low-level API and IO abstraction, so it provides uniform interface for both sockets as well as for asynchronous libraries such as EventMachine and Cool.io.
The important thing about AMQ-Client is that it shouldn’t do any assumptions, it should just implement AMQP API in Ruby. The only exception is the AMQP
Basic class which is just a bunch of methods, so I put them to the class where it makes sense to have them, so the API seems more logical and significantly easier to use.
On top of the AMQ-Client there can be implemented various opinionated clients which can make usage of AMQP easier. Implementing of a good AMQP abstraction isn’t easy, so creating another clients should be encouraged. Typical stuff which should be taken care about on this layer: reconnecting, caching of queues / exchanges, behind-scene channel creation, simplified API, RPC …
require "amq/client/adapters/socket" AMQ::Client::SocketClient.connect(:host => "localhost") do |client| # ... end
- host (defaults to
- port (defaults to
- user (defaults to “guest”)
- pass (defaults to “guest”)
- vhost (default to
- timeout (defaults to
- logging (defaults to
- ssl (defaults to
- broker if you want to load broker-specific extensions (defaults to
AMQ::Client::SocketClient.connect AMQ::Client::SocketClient.connect(:port => 5672) AMQ::Client::SocketClient.connect("amqp://")
require "logger" AMQ::Client.logging = true AMQ::Client.logger = MyLogger.new(STDERR)
AMQ::Client.logging is true but the
AMQ::Client.logger isn’t initialized, it will require
logger library from the Ruby stdlib and assign an instance of this logger to
If you want to be able to log messages just from specified classes or even instances, just make the instance respond to
#logging and set it to desired value.
AMQ::Client::SocketClient.connect do |client| client.queue("", 1) end
gem install amq-client.
You can always find nightly builds at gems.101ideas.cz. You can install them thusly:
wget http://gems.101ideas.cz/amq-client-nightly.gem gem install amq-client-nightly.gem
If you use Bundler and want to use the very latest version, add this to your Gemfile:
gem ‘amq-client’, :git => ‘https://github.com/ruby-amqp/amq-client.git’
git clone git://github.com/ruby-amqp/amq-client.git