<div dir="ltr">You could also use the exclusive queue consuming functionality instead of having to maintain a token message. �Make sure you're the exclusive consumer of a queue before you connect as a producer.</div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Tue, Feb 18, 2014 at 2:23 AM, Alvaro Videla <span dir="ltr"><<a href="mailto:videlalvaro@gmail.com" target="_blank">videlalvaro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<br>
<br>
Maybe there's an easier solution, but you could try this:<br>
<br>
- Create a queue called "lock" (or whatever name suits you) and<br>
publish just one message to it, which will be the token producers need<br>
to obtain in order to publish messages.<br>
- Start your producers and make them consume just one message from<br>
that queue, ie basic_qos(prefetch-count=1), also tell RabbitMQ that<br>
you will ack the messages. The first producer arriving at the queue<br>
will grab the "token". The other producers will sit idle, waiting for<br>
said token.<br>
- When the producer receives the "token", then it can start publishing<br>
to the actual queue where you want the messages.<br>
- If that consumer crashes or is shut down, then the "token" will be<br>
requeued and some other of your backup producers will grab it, so it<br>
can start publishing.<br>
- if the producer wishes to stop, it can basic_reject(requeue=true)<br>
the "token", so another producer can grab it and start publishing.<br>
<br>
Regards,<br>
<br>
Alvaro<br>
<br>
On Tue, Feb 18, 2014 at 3:06 AM, Tarun Mistry <<a href="mailto:tarun.mistry@gmail.com">tarun.mistry@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> i'm new to RabbitMQ/AMQP. I am trying to solve an application level<br>
> high-availability problem and belive i'm not thinking about things in the<br>
> right way, I could use some advice!<br>
><br>
> Here is what I would like to achieve, I could use some help understanding<br>
> the RabbitMQ way of doing it.<br>
><br>
> 1) I have several message producers, only 1 of these is the primary, the<br>
> remainder as all backups.<br>
> 2) The primary is defined as the process that controls a single queue and<br>
> can post messages to it.<br>
> 3) If the primary process fails, I want a backup to take over immediately.<br>
> 4) All backups are in a race to get control of the queue (from 2)<br>
> 5) Once a backup gains control, it is now the primary.<br>
><br>
> Using Rabbit speak, I feel like I need something called an "exclusive<br>
> producer".<br>
><br>
> Do I need to fudge this by introducing a second queue and having all the<br>
> processes connect to this using the "exclusive consumer" pattern, and then<br>
> use this to determine who can control the main queue?<br>
><br>
> Appreciate any advice<br>
><br>
> Cheers<br>
> TM<br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> rabbitmq-discuss mailing list<br>
> <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
> <a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
You received this message because you are subscribed to the Google Groups "rabbitmq-discuss" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:rabbitmq-discuss%2Bunsubscribe@googlegroups.com">rabbitmq-discuss+unsubscribe@googlegroups.com</a>.<br>
To post to this group, send email to <a href="mailto:rabbitmq-discuss@googlegroups.com">rabbitmq-discuss@googlegroups.com</a>.<br>
Visit this group at <a href="http://groups.google.com/group/rabbitmq-discuss" target="_blank">http://groups.google.com/group/rabbitmq-discuss</a>.<br>
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank">https://groups.google.com/groups/opt_out</a>.<br>
</font></span></blockquote></div><br></div>