RabbitMQ Connection and Queue Declaration

  • Share this:

Code introduction


This function establishes a connection to a RabbitMQ server and declares a queue. It accepts the host address and port as parameters.


Technology Stack : Pika

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_channel_queue_connection(host, port):
    import pika
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host, port=port))
    channel = connection.channel()
    channel.queue_declare(queue='random_queue')
    return connection, channel                
              
Tags: