<br><br><div class="gmail_quote">On Mon, Jan 24, 2011 at 3:17 PM, Matthias Radestock <span dir="ltr"><<a href="mailto:matthias@rabbitmq.com">matthias@rabbitmq.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Sam Duncan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If you use a topic exchange and create a queue for each consumer, you get a copy of each message in each queue filtered by your queue bindings.<br></blockquote></div></blockquote><div><br></div><div>I tried this, but it still didn't seem to work.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote>
<br></div>
A direct exchange would probably work too, unless you need bindings with wildcards.<br>
<br>
If you haven't done so already, I recommend reading <a href="http://www.rabbitmq.com/tutorial-three-python.html" target="_blank">http://www.rabbitmq.com/tutorial-three-python.html</a><br>
<br></blockquote><div><br></div><div>I have read this, thanks. </div><div><br></div><div>Here is an attempt that uses two fanout exchanges and two queues, one bound to each exchange with '#'. You would think (well, I would think) that any message sent to either of these fanout exchanges is going to go to every consumer of every queue bound to the appropriate exchange.</div>
<div><br></div><div>However, what happens in practice is only one receiver at a time gets a message.</div><div><br></div><div>Fire up two (or more) instances of app2.py and then run app1.py (which currently just sends a message and exits). How can I change this so that all the instances of app2.py receive all messages sent through the 'from_web_exchange'?</div>
<div><br></div><div>app1.py:</div><div><div><font class="Apple-style-span" face="'courier new', monospace">#!/usr/bin/env python</font></div><div><font class="Apple-style-span" face="'courier new', monospace">import pika</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">connection = pika.AsyncoreConnection(pika.ConnectionParameters(</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> host='localhost'))</font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel = connection.channel()</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_web_exchange = channel.exchange_declare(exchange="from_web_exchange",type="fanout")</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">from_worker_exchange = channel.exchange_declare(exchange="from_worker_exchange", type='fanout')</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_builders_queue = channel.queue_declare(queue='frombuilders', auto_delete=True)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_web_queue = channel.queue_declare(queue='fromweb', auto_delete=True)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">channel.queue_bind(exchange='from_web_exchange', queue=from_web_queue.queue, routing_key="#")</font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel.queue_bind(exchange='from_worker_exchange', queue=from_builders_queue.queue, routing_key="#")</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel.basic_publish(exchange='from_web_exchange',</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> routing_key='does_it_matter',</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> body='Hello World!')</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">print " [x] Sent 'Hello World!'"</font></div><div><font class="Apple-style-span" face="'courier new', monospace">connection.close()</font></div>
</div><div><br></div><div>app2.py:</div><div><div><font class="Apple-style-span" face="'courier new', monospace">#!/usr/bin/env python</font></div><div><font class="Apple-style-span" face="'courier new', monospace">import pika</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">import sys</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">connection = pika.AsyncoreConnection(pika.ConnectionParameters(</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> host='localhost'))</font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel = connection.channel()</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_web_exchange = channel.exchange_declare(exchange="from_web_exchange",type="fanout")</font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_worker_exchange = channel.exchange_declare(exchange="from_worker_exchange", type='fanout')</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">from_builders_queue = channel.queue_declare(queue='frombuilders', auto_delete=True)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">from_web_queue = channel.queue_declare(queue='fromweb', auto_delete=True)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel.queue_bind(exchange='from_web_exchange', queue=from_web_queue.queue, routing_key="#")</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">channel.queue_bind(exchange='from_worker_exchange', queue=from_builders_queue.queue, routing_key="#")</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">#channel.queue_declare(queue='hello')</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">print ' [*] Waiting for messages. To exit press CTRL+C'</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">arg = "No-arg"</font></div><div><font class="Apple-style-span" face="'courier new', monospace">#print len(sys.argv)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">if (len(sys.argv) == 2):</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> arg = sys.argv[1]</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">def callback(ch, method, properties, body):</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> print " [x] Received %r" % (body,)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> channel.basic_publish(exchange='from_worker_exchange',</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> routing_key="#", # key.frombuilders</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> body= arg + " python approves of " + body)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">channel.basic_consume(callback,</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> queue=from_web_queue.queue,</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> no_ack=True)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">pika.asyncore_loop()</font></div><div><br></div></div>
<div> <br>Thanks in advance,</div><div>Dan</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Regards,<br><font color="#888888">
<br>
Matthias.</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">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>
</div></div></blockquote></div><br>