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 server and declares a queue. It accepts host address, port, virtual host, and queue name as parameters.
Technology Stack : Pika
Code Type : Function
Code Difficulty : Intermediate
def create_queue_connection(host, port, virtual_host, queue_name):
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=host, port=port, virtual_host=virtual_host))
channel = connection.channel()
channel.queue_declare(queue=queue_name)
return connection, channel