[rabbitmq-discuss] private exchange name generation

Matthew Sackman matthew at rabbitmq.com
Mon Apr 9 17:28:24 BST 2012


On Mon, Apr 09, 2012 at 07:59:25PM +0400, Matwey V.  Kornilov wrote:
> It is hard to avoid collisions. If I create private exchange and its names 
> and arguments coincide with such of other one, then there is no way to 
> detect the collision. If type or args are different then I can detect it and 
> try to regenerate the name.

Yeah, you can't actually solve that one robustly. The closest you can
get is to do a passive declare immediately before and hope it errors,
but that's a race condition anyway. Alas, tx does not capture resource
creation.

It's pretty yucky, but you could use a queue by the same name with
"exclusive" to act as a lock. Thus:

1. MyGuid = make_me_a_guid()
2. queue.declare (name = MyGuid, exclusive = true)
3. (if it hasn't errored) exchange.declare (name = MyGuid)

The reason that should work is because you can't redeclare an exclusive
queue unless you're the owner of it (i.e. you created it in the first
place). Thus on collision, you'll fail at step 2, even though step 3
would pass. Yes, it's yucky and a waste of resources, but it's the best
I can think of. Don't delete the queue until after you've deleted the
exchange.

Matthew


More information about the rabbitmq-discuss mailing list