AmqpInit

Mailerq-amqpinit is a simple Linux application for setting up queues and exchanges in RabbitMQ. It is an application independent from MailerQ, and can be helpful in, for example, startup scripts to ensure that a RabbitMQ server is correctly configured. It takes a JSON string from standard input, and creates all the exchanges and queues that are defined in that file.

Installation

The application is stored in our APT repository. If you have already enabled our APT repository, you can install it with this command:

sudo apt install mailerq-amqpinit

Running

You typically run this script with one command line argument, and you pipe the JSON input into the program:

amqpinit amqp://user:password@hostname/vhost < input.json

The amqp:// address holds the address of a RabbitMQ server.

Format of the JSON input file

The JSON input file typically holds a JSON array with all the resources (queues, exchanges and bindings) that are to be created. For example:

[ {
    "type":         "queue",
    "name":         "my-queue",
    "durable":      true,
    "arguments": {
        "x-queue-type": "classic"
    }
}, {
    "type":         "exchange",
    "name":         "my-exchange",
    "durable":      true,
    "arguments": {
        "x-max-length": 1000
    }
}, {
    "type":         "exchange",
    "name":         "my-other-exchange",
    "exchangetype": "fanout",
    "durable":      true
}, {
    "type":         "binding",
    "exchange":     "my-exchange",
    "queue":        "my-queue",
    "routingkey":   "my-routing-key"
}, {
    "type":         "binding",
    "exchange":     "my-exchange",
    "target":       "my-other-exchange",
    "routingkey":   "my-routing-key"
} ]

For each item in the array, the following properties are supported:

Not all properties are meaningful for all resource types. For example, the "exchangetype", "queue", "target" and "routingkey" properties only make sense for exchanges. The properties "durable", "autodelete", "passive", "exclusive" and "internal" are all booleans and are available for completeness because the AMQP protocol supports them. Realistically, only the "durable" property is useful.