[rabbitmq-discuss] AMQP ruby client

Aman Gupta rabbitmq at tmm1.net
Fri Jul 18 02:57:43 BST 2008


I've just finished a simple high level api, and committed several examples
showing off direct, topic, fanout and rpc style messaging over rabbitmq:
  http://github.com/tmm1/amqp/tree/master/examples/pingpong.rb
  http://github.com/tmm1/amqp/tree/master/examples/clock.rb
  http://github.com/tmm1/amqp/tree/master/examples/stocks.rb
  http://github.com/tmm1/amqp/tree/master/examples/hashtable.rb

The API revolves around an MQ object, which corresponds 1:1 with an AMQP
channel. An AMQP connection is created automatically by the MQ class (on
demand), so you don't have to worry about connection, channel or sessions.
In the simplest case, MQ objects allow publishing to exchanges and reading
from queues:

  amq = MQ.new

  amq.queue('queue_name').subscribe{ |msg|
    puts "i got a message: #{msg}"   # msg == "hello world"
  end

  amq.direct.publish('hello world', :key => 'queue_name')

  Aman Gupta

On Sat, Jul 12, 2008 at 2:45 AM, Aman Gupta <rabbitmq at tmm1.net> wrote:

> I've been working on a Ruby/EventMachine AMQP client over the past few days
> and I have a simple client up and running:
>
>     def receive_data data
>       Frame.extract(data).each do |frame|
>         # log 'got a frame', frame
>
>         case method = frame.payload
>         when Protocol::Connection::Start
>           send Protocol::Connection::StartOk.new({:platform =>
> 'Ruby/EventMachine',
>                                                   :product => 'AMQP',
>                                                   :information => '
> http://github.com/tmm1/amqp',
>                                                   :version => '0.0.1'},
>                                                  'AMQPLAIN',
>                                                  {:LOGIN => 'guest',
>                                                   :PASSWORD => 'guest'},
>                                                  'en_US')
>
>         when Protocol::Connection::Tune
>           send Protocol::Connection::TuneOk.new :channel_max => 0,
>                                                 :frame_max => 131072,
>                                                 :heartbeat => 0
>
>           send Protocol::Connection::Open.new :virtual_host => '/',
>                                               :capabilities => '',
>                                               :insist => false
>
>         when Protocol::Connection::OpenOk
>           send Protocol::Channel::Open.new, :channel => 1
>         end
>       end
>     end
>
> Feedback and ideas for a higher-level queue/exchange/binding API are
> welcome.
>
>   Aman Gupta
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20080717/39e40a5f/attachment.htm 


More information about the rabbitmq-discuss mailing list