<div dir="ltr">I've just finished a simple high level api, and committed several examples showing off direct, topic, fanout and rpc style messaging over rabbitmq:<div><br></div><div> <a href="http://github.com/tmm1/amqp/tree/master/examples/pingpong.rb">http://github.com/tmm1/amqp/tree/master/examples/pingpong.rb</a></div>
<div> <a href="http://github.com/tmm1/amqp/tree/master/examples/clock.rb">http://github.com/tmm1/amqp/tree/master/examples/clock.rb</a></div><div> <a href="http://github.com/tmm1/amqp/tree/master/examples/stocks.rb">http://github.com/tmm1/amqp/tree/master/examples/stocks.rb</a></div>
<div> <a href="http://github.com/tmm1/amqp/tree/master/examples/hashtable.rb">http://github.com/tmm1/amqp/tree/master/examples/hashtable.rb</a></div><div><br></div><div>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:</div>
<div><br></div><div> amq = MQ.new</div><div><br></div><div> amq.queue('queue_name').subscribe{ |msg|</div><div> puts "i got a message: #{msg}" # msg == "hello world"<br></div><div> end</div>
<div><br></div><div> amq.direct.publish('hello world', :key => 'queue_name')</div><div><br></div><div> Aman Gupta<br><br><div class="gmail_quote">On Sat, Jul 12, 2008 at 2:45 AM, Aman Gupta <<a href="mailto:rabbitmq@tmm1.net">rabbitmq@tmm1.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>I've been working on a Ruby/EventMachine AMQP client over the past few days and I have a simple client up and running:<br>
</div><div><br></div><div><div><span> def receive_data data</span></div>
<div><span> Frame.extract(data).each do |frame|<br></span></div><div><span> # log 'got a frame', frame</span></div>
<div><span> </span></div><div><span> case method = frame.payload</span></div>
<div><span> when Protocol::Connection::Start</span></div><div><span> send Protocol::Connection::StartOk.new({:platform => 'Ruby/EventMachine',</span></div>
<div><span> :product => 'AMQP',</span></div><div><span> :information => '<a href="http://github.com/tmm1/amqp" target="_blank">http://github.com/tmm1/amqp</a>',</span></div>
<div><span> :version => '0.0.1'},</span></div><div><span> 'AMQPLAIN',</span></div>
<div><span> {:LOGIN => 'guest',</span></div><div><span> :PASSWORD => 'guest'},</span></div>
<div><span> 'en_US')</span></div><div><span><br>
</span></div><div><span> when Protocol::Connection::Tune</span></div><div><span> send Protocol::Connection::TuneOk.new :channel_max => 0,</span></div>
<div><span> :frame_max => 131072,</span></div><div><span> :heartbeat => 0</span></div>
<div><span><br></span></div><div><span> send Protocol::Connection::Open.new :virtual_host => '/',</span></div>
<div><span> :capabilities => '',</span></div><div><span> :insist => false</span></div>
<div><span><br></span></div><div><span> when Protocol::Connection::OpenOk</span></div>
<div><span> send Protocol::Channel::Open.new, :channel => 1</span></div><div><span> end</span></div>
<div><span> end</span></div><div><span> end</span></div>
<div><br></div><div>Feedback and ideas for a higher-level queue/exchange/binding API are welcome.</div><div><br></div><font color="#888888"><div> Aman Gupta</div></font></div>
</blockquote></div><br></div></div>