You can download this code by clicking the button below.
This code is now available for download.
This function creates a RabbitMQ queue that is exclusive (meaning it only exists for the duration of the connection) and durable (meaning its content is not lost if the server restarts).
Technology Stack : pika, RabbitMQ
Code Type : RabbitMQ operation
Code Difficulty : Intermediate
import random
import pika
from pika import BasicProperties
from pika.exchange_type import ExchangeType
def create_queue_with_exclusive_and durable_queue():
# Connect to RabbitMQ server
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
# Declare an exclusive and durable queue
queue_name = channel.queue_declare(queue='', exclusive=True, durable=True).method.queue
# Close the connection
connection.close()
return queue_name