python-3.xrabbitmqpika

How to verify that Pika 1.0.0 "basic_publish" method executes successfully


In Pika 0.13.1 this code worked as expected:

    if channel.basic_publish(exchange='exchange', routing_key='', properties=properties, body=message_as_string):
        pass
    else:
        raise RuntimeException("Fail!")

After upgrading to Pika 1.0.0, the "basic_publish" function don't seem to return boolean anymore, but I haven't figured out exactly what it returns (if anything), and how to verify that the function executes successfully. Based on my understanding of Pika's source code, I'm thinking basic_publish doesn't return anything but rather raises exceptions if anything happens.

Have anyone else figured out out to verify that "basic_publish" executes successfully?


Solution

  • If no exceptions are thrown, the publish has been sent successfully. You should consider using the mandatory flag and enabling publisher confirms to be notified when your message is routed and queued by RabbitMQ. The success of the basic_publish function is only one part of the equation.