[rabbitmq-discuss] Create exchanges and queues beforehand

Stefano Ghio steghio at eng.it
Mon Nov 14 12:22:18 GMT 2011


Cheers,

I was fiddling with the Topic examples and I ran into a problem. If I 
start the client "ReceiveLogsTopic" before the sender "EmitLogTopic" I 
see everything working fine. Sender sends and client receives and 
displays right.

However, if I start the sender before the client, the message gets sent 
but then nothing happens, the queue appears to be empty and the client 
keeps waiting for nothing.

I think that's correct since the queue is created at runtime and is 
destroyed when there's nothing more to do with it as explained in the 
documentation:

channel.exchangeDeclare(*exchangeName*,*"direct"*,*true*);
String*queueName*  = channel.queueDeclare().getQueue();
channel.queueBind(*queueName*,*exchangeName*,*routingKey*);

This will actively declare the following objects, both of which can be 
customised by using additional parameters. Here neither of them have any 
special arguments.

 1. a durable, non-autodelete exchange of "direct" type
 2. a non-durable, exclusive, autodelete queue with a generated name



What I would like to do instead is (example):

1)
create 3 exchanges: EXA, EXB and EXC
for every exchange, create 2 queues and bind them to it: Q1 and Q2. All 
queues have the same name but are not the same object (see attached PNG 
if needed)
2)
send a message to be queued in queue Q1 through EXA
send the same message to be queued in queue Q1 through EXB
message then is queued in two different queues which happen to have the 
same name but are binded to different exchanges
3)
poll Q1 through EXA to read messages and delete message
poll Q1 through EXB to read messages and leave message there
message then is no longer in EXA-Q1 but is still available through EXB-Q1

I don't and can't know if and when someone will try to send or read 
messages.

I guess it would require me to declare and bind a queue beforehand, 
maybe by using 3 classes: setUpExchangeAndQueues, sendMessage, 
pollMessages, but I'm a bit at loss here, could anyone point me in the 
right direction?

I read that:

If several clients want to share a queue with a well-known name, this 
code would be appropriate:

channel.exchangeDeclare(*exchangeName*,*"direct"*,*true*);
channel.queueDeclare(*queueName*,*true*,*false*,*false*,*null*);
channel.queueBind(*queueName*,*exchangeName*,*routingKey*);

This will actively declare:

 1. a durable, non-autodelete exchange of "direct" type
 2. a durable, non-exclusive, non-autodelete queue with a well-known name

Tried it but failed.

Please advise, I'm going crazy on this.

Thank you,

have a nice day
-- 
Dr. Stefano Ghio - ENG Engineering Italy

Website: http://groglogs.blogspot.com/

*If you received this message but you are not its recipient, please 
ignore it and warn me, thank you.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20111114/c323acb7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exq.PNG
Type: image/png
Size: 8402 bytes
Desc: not available
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20111114/c323acb7/attachment.png>


More information about the rabbitmq-discuss mailing list