Search code examples
node.jsrabbitmqnode-amqplib

Get a list of exchanges, bindings, queues from RabbitMQ by NodeJS


Sometimes it is needed to recreate bindings and queues at RabbitMQ by NodeJS. I need to unbind, clear and delete them programaticaly. I can save what I do and revert later. I use amqplib. It confuses that it does not provide functionality that could list them. http://www.squaremobius.net/amqp.node/channel_api.html Is it possible? What is a reason that it is absent?


Solution

  • amqplib does not support getting a list of exchanges, bindings and queues from RabbitMQ because this is not part of the AMQP protocol.

    RabbitMQ does provide a management plugin which includes an HTTP based API. Alternatively you could maintain a list of exchanges, queues and bindings separately, and use node to assert these, however you still wouldn't be able to assert vhosts, users and policies with amqplib. Instead you would have to install the previously mentioned management plugin and use HTTP.

    Libraries like Rascal (disclaimer - I'm the author) do provide limited functionality for automatically creating RabbitMQ objects too. Rascal can be configured to assert vhosts (using http), exchanges, queues and bindings (using amqplib) on application startup, but will not delete extra objects, and currently cannot create users or policies.

    Another option is to backup and restore RabbitMQ's entire config. I've only used the Management UI to do this, but it may be supported by the HTTP API. However, once again this will not delete objects that were added after the backup.

    For completeness, you could use the RabbitMQ command line tools to assert the configuration. Tools like Puppet, Chef and Ansible are frequently used to automate this, but considering you asked about node/amqplib I assume this is not acceptable.

    Any attempt to re-define an existing object (e.g. changing an exchange type, or adding different x-attributes to queues) using any of the above methods will fail.