<br><br><div class="gmail_quote">On 17 August 2011 10:39, Michael Bridgen <span dir="ltr"><<a href="mailto:mikeb@rabbitmq.com">mikeb@rabbitmq.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Pete,<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have been playing with rabbitmq and am thinking through some common<br>
scenarios I think I will need to deal with, I was wondering if anyone<br>
would be able to take the time to read my thoughts and validate them or<br>
throw a few more options in/give me some article links?<br>
<br>
I have a topic exchange and need to attach some consumers to process<br>
messages.<br>
<br>
If I attach a consumer with no queue name, a unique one time queue will<br>
be created and I can bind the exchange to this queue using a routing key<br>
like 'animal.mammals.#'.<br>
</blockquote>
<br></div>
Not quite; you have to create the queue with an empty name, then consume from it using the name you get back in queue.declare_ok (and then bind it to the exchange).<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This is great until<br>
<br>
- the consumer crashes, meaning the exchange will drop all messages (or<br>
they get rejected depending on the publish settings I use)<br>
or<br>
</blockquote>
<br></div>
Yes, that can happen. Though if the queue isn't exclusive or auto_delete (and thereby destroyed when the connection drops or consumer goes away), it will happily collect messages until the consumer returns. Of course, you'd have to have recorded its name somewhere, or generated the name yourself in a way you can repeat.<div class="im">
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- I need another consumer to process animals.mammals.#, which I can't do<br>
as I am using a one time queue and adding another will mean each message<br>
is delivered to 2 queues.<br>
</blockquote>
<br></div>
What is the problem with delivering to two queues? If you are using a topic exchange, creating an anonymous, exclusive queue for each consumer is usually appropriate.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Are the above assumptions correct?<br>
<br>
<br>
So my second option is to use a named queue. I attach a consumer with a<br>
queue name and bind the exchange to this queue using a routing key like<br>
'animal.mammals.#'.<br>
<br>
Now if I need another consumer I simply bring another one up and attach<br>
it to the same queue name, and they get the messages in round robin<br>
which is great.<br>
</blockquote>
<br></div>
It is certainly an established pattern to use a durable, named queue for sharing out messages. Queues do double duty in AMQP -- firstly as "work queues" of this kind, secondly as buffers for transmission.<br></blockquote>
<div><br></div><div>That's good to know, after experimenting this is the thinking I have come round to as it allows the consumers to die if they need to and the queues will still be written to, using a named queue also enables more than one consumer to attach to a queue and receive the messages in round robin, which is a nice quick way to add process capacity if it's ever required.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Take care with the order in which you do things, or at least be aware that unless you set a prefetch value, the first consumer will get all the messages in the queue at that time.</blockquote><div><br></div><div>I noticed that with my experiments, prefetch is now set.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
What's not so great is if I then decide to attach a consumer to this<br>
queue name (maybe by accident) and bind the exchange to a routing key<br>
'animal.mammals.rabbit'<br>
<br>
Then the queue gets 2 copies of each message. Is there any way to avoid<br>
this other than careful management of bindings? Maybe a way of telling<br>
the exchange to only deliver the message once to a given queue?<br>
</blockquote>
<br></div>
No, it won't get two copies. The routing will only ever deliver any given message once to a queue.<br>
<br>
The combination of wildcard routing and round-robin is unusual. Would you go into more detail about what you are trying to achieve?<br></blockquote><div><br></div><div>I think I could have confused the issue here somewhat - because of how the tutorials are laid out I mistakenly thought that the consumer could consume on a given routing key, rather than the routing key just being a binding between an exchange and a queue. So I was thinking I was consuming on a routing key, whereas in reality that's not the case.</div>
<div><br></div><div>The tutorials (and further experimentation) It's been a useful exercise in finding out just how flexible rabbitmq is, and with that flexibility comes the potential to really break the queues and bindings (especially if the application is allowed to blindly create queues and bindings).</div>
<div><br></div><div>I am going to go with an approach that means bindings and queues must be manually created, and only give the application code permission to write to the exchanges, and read from the queues.</div><div><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
<br>
--Michael<br>
______________________________<u></u>_________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.<u></u>rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/<u></u>cgi-bin/mailman/listinfo/<u></u>rabbitmq-discuss</a><br>
</blockquote></div><br>