You can download this code by clicking the button below.
This code is now available for download.
This function creates a connection to RabbitMQ and returns a channel object. It accepts host name, port, and virtual host as parameters and connects to RabbitMQ using default authentication credentials.
Technology Stack : RabbitMQ, Pika
Code Type : The type of code
Code Difficulty : Intermediate
import random
import pika
import json
def random_channel_connection(host, port, virtual_host):
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters(host, port, virtual_host, credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
return channel