markiz / amq-client

A WORK IN PROGRESS: Low-level AMQP 0.9.1 client which is supposed to back higher-level AMQP libraries like amqp gem or bunny

Home Page:http://groups.google.com/group/ruby-amqp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

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

AMQ-Client API

Adapters

require "amq/client/adapters/socket"

AMQ::Client::SocketClient.connect(:host => "localhost") do |client|
  # ...
end

Settings

Available Options

  • host (defaults to "127.0.0.1")
  • port (defaults to AMQ::Protocol::DEFAULT_PORT)
  • user (defaults to “guest”)
  • pass (defaults to “guest”)
  • vhost (default to "/")
  • timeout (defaults to nil)
  • logging (defaults to false)
  • ssl (defaults to false)
  • broker if you want to load broker-specific extensions (defaults to nil)

Usage

AMQ::Client::SocketClient.connect
AMQ::Client::SocketClient.connect(:port => 5672)
AMQ::Client::SocketClient.connect("amqp://")

Logging

require "logger"

AMQ::Client.logging = true
AMQ::Client.logger  = MyLogger.new(STDERR)

If 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 AMQ::Client.logger.

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.

AMQP API

AMQ::Client::SocketClient.connect do |client|
  client.queue("", 1)
end

Installation

Install by gem install amq-client.

Nightly Builds

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 Repository

git clone git://github.com/ruby-amqp/amq-client.git

Links

About

A WORK IN PROGRESS: Low-level AMQP 0.9.1 client which is supposed to back higher-level AMQP libraries like amqp gem or bunny

http://groups.google.com/group/ruby-amqp

License:MIT License


Languages

Language:Ruby 98.8%Language:Shell 1.2%