AMQPLIB - NodeJS - Asserting a Lazy Queue in RabbitMQ

1.2k Views Asked by At

I want to assert a queue in lazy mode into existence via amqplib using nodeJs.

I know I can do this by creating policies, I don't want to do that as its hard to automate right now in the environment we have.

I have tried the following:

        let options = {
            durable: true,
            arguments: {},
            lazy: true, //doesnt work
            mode: "lazy" //doesnt work
        };
        if (job.highQueueLengthExpected) {
            options.arguments["x-queue-mode"] = "lazy"; //doesnt work
            options.arguments["queue-mode"] = "lazy"; //doesnt work
            options["x-queue-mode"] = "lazy"; //doesnt work
        }

        return ch.assertQueue(job.key, options).then(function (ok) {

I am checking the mode of the queue via RabbitMQ's HTTP API by firing

curl  -u guest:guest 'localhost:15672/api/queues/{vhostName}/{queueName}'

For all the options I provide while asserting the queue, the mode comes back as default

1

There are 1 best solutions below

0
On

queueMode: 'lazy'

works for me. In general I think the amqplib option keys are the camel-cased versions of the amqp features or options with the x- removed. For example x-dead-letter-exchange in amqp is deadLetterExchange in amqplib.

This only works with amqplib v0.5.3 and higher.