RabbitMQ Channel Creation with Pika BlockingConnection

  • Share this:

Code introduction


This code creates a Pika BlockingConnection object and uses it to create a channel. This is commonly used for interacting with RabbitMQ.


Technology Stack : Pika

Code Type : Pika Connection and Channel

Code Difficulty : Intermediate


                
                    
import random
from pika import BlockingConnection, ConnectionParameters

def random_channel_connection(host='localhost', virtual_host='/'):
    connection = BlockingConnection(ConnectionParameters(host=host, virtual_host=virtual_host))
    channel = connection.channel()
    return channel                
              
Tags: