[rabbitmq-discuss] Creating Queues and Exchanges on the Fly

Preston Marshall preston at synergy-solutions.biz
Thu Sep 4 02:28:32 BST 2008


Hi all, I have a few questions related to RabbitMQ and tmm1's (Aman  
Gupta) Ruby library for amqp.  I have a situation where I have about 5  
different queues setup like this:

amq.queue('all').bind(amq.topic, :key => "events").subscribe

then inside of the binding, i have something that uses ActiveResource  
to add an event based on the content of the message:

doc = REXML::Document.new object.to_s
EventMessage.create :name => doc.elements['// 
headline'].text.to_s, :home_county =>  
info.headers[:sender].to_s, :acknowledged => false, :external =>  
true, :event_type_id => doc.elements['//typeid'].text.to_i, :status_id  
=> doc.elements['//statusid'].text.to_i, :scope => "#{doc.elements['// 
scope'].text}", :urgency_id => doc.elements['// 
urgencyid'].text.to_i, :severity_id => doc.elements['// 
severityid'].text.to_i, :certainty_id => doc.elements['// 
certaintyid'].text.to_i, :uuid => doc.elements['//identifier'].text.to_s

Now I have an interesting problem which probably requires and  
interesting solution :).  I can successfully pass events through my  
different exchanges, i have a 'all' queue, along with national,  
regional, state, and stateregion.  They all have different routing  
keys that can be used to send to them like for example one key is  
events.us.5.al.4, that in particular creates a queue named stateregion  
and binds to it with a key that listens for messages only for that  
state region, for that state, for that region, for that nation. Now  
what I need to do is setup a queue for events that are going on, as  
the queues I have now only pass new event notifications, not actualy  
communications for those events.  Each new event has a UUID assoicated  
with it, so I was thinking that maybe I should create a new queue when  
a new event message comes in, based on the contents of the message.   
So I would have something like this:

amq.queue('94a2b510-5c4c-012b-a451-001ff34e82f0').bind(amq.topic, :key  
=> "94a2b510-5c4c-012b-a451-001ff34e82f0.posts").subscribe

where in reality I would have something like this, since new events  
will be created and destroyed on the fly, and base the new queue's key  
and name on a message recieved from a "parent" queue.:

amq.queue(doc.elements['//eventuuid'].to_s).bind(amq.topic, :key =>  
"#{doc.elements['//eventuuid']}.posts").subscribe

This queue allows for "posts" or basically pieces of information like  
SMS messages to be passed across the network, while referencing an  
event, which is the UUID.

Is this the only way to this, or if not, the best?  Wisdom tells me  
that if you are doing something that seems really complex and hard,  
there is probably a better and easier way that you haven't seen.  I  
believe that my inexperience with AMQP and its nomenclature is causing  
me massive confusion and strife, which of course I'd love for you guys  
to help me out with.

Thanks,
Preston Marshall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2441 bytes
Desc: not available
Url : http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20080903/280ce718/attachment.bin 


More information about the rabbitmq-discuss mailing list