python – How to send messages from Flask server to RabbitMQ server queue?

I’m trying to send a message from Flask server, which acts as a producer, to a RabbitMQ server queue. The port I’m using to produce the messages is ‘5672’.

I’ve created an exchange and a queue on RabbitMQ’s Management server and the main goal is to receive a message in the server’s queue.

This is the code that I have at the moment, it does not produce any errors and returns that the message has been sent:

def create_bucket(message):
    credentials = pika.PlainCredentials("guest", "guest")
    connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials))
    channel =
    channel.queue_declare(queue="TestQueue", durable=True)
    channel.basic_publish(exchange="TestExchange", routing_key="TestQueue", body=message, properties=pika.BasicProperties(delivery_mode=2))
    return "[x] Message sent %s" % message 

if __name__ == "__main__":, port=5672)

Though the message does not appear in RabbitMQ’s server’s queue.

Are there any resources or ways to send a message from Flask’s server to RabbitMQ’s server queue?

Read more here: Source link