Search code examples
rabbitmqpika

Popping one element from a RabbitMQ queue


I have a queue, and I've stuffed some n elements from it.

I want to take 1 element from it, and then exit the callback.The pika examples all use a callback mechanism, which really does not make sense in the application structure.

Defining a callback as follows

def callback(...):
  do_data_thinggs(...)
  exit(0)

doesn't work, as the message stays in the queue

What's the usual idiom for doing this?


Solution

  • You will want to look at the basic_get method on the channel, have a look at:

    https://github.com/pika/pika/blob/03542ef616a2a849e8bfb0845427f50e741ea0c6/docs/examples/blocking_basic_get.rst for an example, this will block until a message is received.