Search code examples
pythonpython-2.7rabbitmqpika

Rabbitmq Blocking Connection to consume messages from RabbitMQ vs Using the Blocking Connection to get a message from RabbitMQ


I'm pretty confused between the two methods of working with rabbitmq's pika library.

The first is Blocking consume
Second is Blocking basic_get
Can someone please explain in further details about the differences?

Is the difference that Blocking consume is getting messages out of the queue all the time if being sent to, while in the basic_get, we can control more when to get messages out of the queue?


Solution

  • Yes you right.

    basic_get()

    From RabbitMQ perspective it's a pull operation. You can retrieve message when ever you want in your code. In other words it's a sequential operation. You get a message when you ask. Then after that, the client it's not "automatically" fetches new messages. Think of it as a regular call to a REST API.

    bascic_consume()

    From RabbitMQ perspective it's a push operation. You open up a pipe to the server and tell RabbitMQ that "hey as soon as something new arrives, send it to me". This is a very powerful feature, that gives you much higher performance, allows you control number of messages you can process at once and so on.