You can download this code by clicking the button below.
This code is now available for download.
This function creates a connection to a RabbitMQ message queue and declares a randomly named queue. The function accepts three parameters: the address and port of the RabbitMQ server, and the name of the queue.
Technology Stack : Python, RabbitMQ, pika
Code Type : The type of code
Code Difficulty : Intermediate
import random
import pika
def random_queue_connection(host='localhost', port=5672, queue_name='random_queue'):
connection = pika.BlockingConnection(pika.ConnectionParameters(host=host, port=port))
channel = connection.channel()
channel.queue_declare(queue=queue_name)
return connection, channel