Search code examples
pythonpika

pika unable to create quorum queue


i setup amazonMQ with RabbitMQ and try to use Pika to connect and publish messsage:

        credentials = pika.PlainCredentials(MQUSER, MQPW)
        amqs_str='amqps://'+MQUSER+':'+MQPW + '@'+MQURL+':'+str(MQPORT)+'/%2F'
        parameters= pika.URLParameters(amqs_str)
        connection = pika.BlockingConnection(parameters)
        channel= connection.channel()
        channel.queue_declare(queue=MQ_QUEUE_NAME,durable=True)

This will work, but the queue created is classic, and i understand quorum is much better in multi-node rabbitmq server. i search through pika documentation https://pika.readthedocs.io/en/0.10.0/modules/channel.html but couldnt find any settings to set quorum type queue. can anyone advice?


Solution

  • Just tried it out - works by passing the queue type quorum when calling queue_declare.

    Minimal working example. I tested with the rabbitMQ docker image: docker run -d --name rabbitMQ -p 5672:5672 -p 8080:15672 rabbitmq:3-management

    import pika
    con = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
    channel = con.channel()
    channel.queue_declare(queue="test",durable=True,arguments={"x-queue-type": "quorum"})