Pika - Rabbitmq, using Basic.get to cosume single

2019-09-18 16:52发布

问题:

I'm using the method shown here like this:
while method_frame is None: method_frame, header_frame, method_frame= channel.basic.get("test_queue)

It's looks like this polling is not so efficient this way, because basic get is working also if queue is empty, and bringing empty messages.

I need a kind of logic which takes a single message, only when I have the opportunity to take care of it, that's why I chose basic.get and not basic.consume.

Do anybody has and idea for doing a more efficient polling maybe by using some pika's library other mechanism?

回答1:

Try using basic.consume(ack=true) with basic.qos(prefetch_count=1).

You need to see how to do that with your particular library