[rabbitmq-discuss] How do the Producer gets response from the subscribers

Matthias Radestock matthias at rabbitmq.com
Mon Sep 23 10:16:53 BST 2013


On 19/09/13 13:15, ramkkk wrote:
> Producer the sends a command to the consumer  to spawn the process . so each
> consumer has to give the response back to the Producer ..
>
>   but i am not getting the response back to the Producer, consumer is going
> on the infinite loop...
> [...]
> consumer code
> [...]
>      def on_request(self,ch, method, props, body):
>          self.spawn_processes(2)
>          self.response = [process.pid for process in self.spawned_processes]
>          ch.basic_publish(exchange='logs',
>                       routing_key='',
>                       properties=pika.BasicProperties(correlation_id = \
>                                                       props.correlation_id,
>                                                       delivery_mode=2 ,
>                                                       ),
>
>                       body=str(self.response))
>          ch.basic_ack(delivery_tag = method.delivery_tag)

The consumer is publishing the response to the 'logs' exchange with a '' 
routing key, whereas...

> Producer
> [...]
>      def __init__(self):
>          self.connection = pika.BlockingConnection(pika.ConnectionParameters(
>                  host='localhost'))
>          self.channel = self.connection.channel()
>          self.channel.exchange_declare(exchange='logs',
>                           type='fanout')
>          result = self.channel.queue_declare(exclusive=True)
>          self.callback_queue = result.method.queue
>
>          self.channel.basic_qos(prefetch_count=1)
>          self.channel.basic_consume(self.on_response, no_ack=True,
>                                     queue=self.callback_queue)

...the producer is expecting replies on an exclusive, server-named queue.

Clearly that isn't going to work. And because the 'logs' exchange is 
also the exchange on which the consumer queue is bound you end up with 
the 'infinite loop' at the consumer since the response published by the 
consumer will be consumed by the consumer!

You need to change your consumer to publish the response to the default 
exchange ('') with the routing_key taken from props.reply_to of the request.

Matthias.


More information about the rabbitmq-discuss mailing list