Change Log

Version 3.0

Peer

@queue_name has been removed. This is replaced by optional argument in Peer::listen().

@name attribute added. Taken from constructor. This is a convenience variable for generic identification. It is not used for anything.

Peer::listen(args={}):

No longer creates a new queue by default. It will use the default private queue. If you provide a queue argument, then it will create a new queue and keep track of it as a listen queue internally which will be destroyed on disconnect(). Also takes an optional exchange argument. If provided, it will bind the new queue to that exchange.

For example say you want to create a service which listens on its private queue. Furthermore you want to receive messages on the default AMQP Fanout queue. Here's a working example:

#!/usr/bin/env ruby

require 'haredo/peer'

$mq_host     = 'localhost'
$mq_username = 'guest'
$mq_password = 'guest'
$queue       = 'doesntmatter'

class Service < HareDo::Peer

  def initialize(name)
    super name
    connect( :host      => $mq_host,
             :user      => $mq_username, 
             :password  => $mq_password,
             :vhost     => '' )    

    @queue.bind('amq.fanout')
  end

  def serve(msg)
    dump_message msg
  end
  
end

service = Service.new('service')
service.listen({:blocking=>false})

# Client

client = HareDo::Peer.new()
client.connect(:user=>$mq_username, :password=>$mq_password, :host=>$mq_host)

client.exchange = client.channel.fanout('amq.fanout')
client.send($queue, :headers => { :testing => 1 })

# Cleanup

client.disconnect()
service.disconnect()