rabbitmq-c examples - producer/consumer work queue not working ???

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

rabbitmq-c examples - producer/consumer work queue not working ???

ktran0003
I tried out the producer/consumer examples included in  rabbitmq-c as follows:
One producer and two consumers

In two separate terminal windows:  ./amqp_consumer localhost 5672
In one terminal window:  %./amqp_producer localhost 5672 1 6

Both consumers show:
6737 ms: Received 1 - 1 since last report (0 Hz)
6737 ms: Received 2 - 1 since last report (16949 Hz)
7739 ms: Received 3 - 1 since last report (0 Hz)
8737 ms: Received 4 - 1 since last report (1 Hz)
9738 ms: Received 5 - 1 since last report (0 Hz)
10737 ms: Received 6 - 1 since last report (1 Hz)

This is a surprise to me.  I thought the messages should be sent round-robin to both consumers (like the python example) so they would not receive everything like a fanout.
Do I miss something?  If this is the way it's supposed to work, how I change the code to make it work like a work queue?

Thanks,
-Kim





_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: rabbitmq-c examples - producer/consumer work queue not working ???

Michael Klishin-2
 On 13 June 2014 at 23:32:01, [hidden email] ([hidden email]) wrote:
> > This is a surprise to me. I thought the messages should be sent  
> round-robin to both consumers (like the python example) so they  
> would not receive everything like a fanout.
> Do I miss something? If this is the way it's supposed to work, how  
> I change the code to make it work like a work queue?

This example:
https://github.com/alanxz/rabbitmq-c/blob/master/examples/amqp_producer.c

uses a direct exchange that will deliver a message to multiple queues if multiple
queues were bound with the same routing key (queue names do not matter).

This tutorial:
http://www.rabbitmq.com/tutorials/tutorial-two-python.html

uses the default exchange which all queues are bound to automatically
with routing key = queue name. because 2 queues cannot have the same name,
we cannot get into the situation above.

So make sure the example you use is equivalent to tutorial 2: uses basic.qos = 1 and default
exchange. Or bind queues to amq.direct with different routing keys (but it is
a needless complication for what tutorial 2 covers).

See http://www.rabbitmq.com/tutorials/amqp-concepts.html if something isn't clear.
--  
MK  

Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

rabbitmq-c examples - producer/consumer work queue not working ???

alan.antonuk
In reply to this post by ktran0003
The amqp_consume example sets no_ack = 1, so the broker sends messages to consumers as fast as possible without waiting for any acknowledgement from clients.

To make it work more like a work-queue, you'd need to set no_ack = 0, requiring the consumer to send a basic.ack (amqp_basic_ack). In addition you'll also need to set a qos (using amqp_basic_qos) which will limit the number of unacked messages that each consumer can have. (to be pedantic - the qos parameter is per-channel: see: http://www.rabbitmq.com/consumer-prefetch.html )

-Alan

On Fri Jun 13 2014 at 12:30:38 PM, <[hidden email]> wrote:
I tried out the producer/consumer examples included in  rabbitmq-c as follows:
One producer and two consumers

In two separate terminal windows:  ./amqp_consumer localhost 5672
In one terminal window:  %./amqp_producer localhost 5672 1 6

Both consumers show:
6737 ms: Received 1 - 1 since last report (0 Hz)
6737 ms: Received 2 - 1 since last report (16949 Hz)
7739 ms: Received 3 - 1 since last report (0 Hz)
8737 ms: Received 4 - 1 since last report (1 Hz)
9738 ms: Received 5 - 1 since last report (0 Hz)
10737 ms: Received 6 - 1 since last report (1 Hz)

This is a surprise to me.  I thought the messages should be sent round-robin to both consumers (like the python example) so they would not receive everything like a fanout.
Do I miss something?  If this is the way it's supposed to work, how I change the code to make it work like a work queue?

Thanks,
-Kim




_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss