MailerQ result messages

MailerQ result messages

The MailerQ result message queues are used by MailerQ to publish the results of delivery attempts. The messages on the result queues are JSON encoded.

Postmastery developed an agent which uses a RabbitMQ queue to collect delivery results using AMQP and forwards the result messages in batches to an API endpoint using HTTP. The agent is used to push the result of successful, failed and retried deliveries as newline delimited JSON to an API endpoint of Postmastery Console.

Configure MailerQ

The configuration depends on how RabbitMQ is setup by MailerQ. First check if the RabbitMQ default exchange is used. In that case the rabbitmq-exchange setting is empty. With the default exchange it is not possible to have multiple applications reading the result messages. MailerQ strongly recommends to use a named exchange which allows for a more flexible setup.

Default exchange

When using the default exchange, in the RabbitMQ configuration of MailerQ, make sure the results and the retry events are queued in a single queue named “results”.

rabbitmq-results:  results rabbitmq-success: rabbitmq-failure: rabbitmq-retry:    results

Messages in the results queue may contain the raw content of the email in the “mime” field. This is not needed and can be disabled by setting the “keepmime” field to false during submission. See also section "Keep messages after delivery” on JSON for outgoing messages.

In MailerQ 5.15.0 the rabbitmq-results and rabbitmq-retry settings are no longer supported. Use the rabbitmq-success, rabbitmq-failure settings instead. The rabbitmq-retries must be set to retries or outbox and cannot be read by the agent.

rabbitmq-success: results rabbitmq-failure: results

Named exchange

When a named exchange is used it is possible to setup multiple queues for the same routing keys (types of messages). The mqresults agent will be used to create a dedicated queue and setup necessary bindings from the exchange to the queue.

Open the MailerQ configuration file and make a note of the exchange name. This can be for example:

rabbitmq-exchange: mailerq

The rabbitmq-retries must be set to “retries”. This will allow the agent to see deferred messages. MailerQ will also bind “retries” to the outbox queue.

rabbitmq-retries: retries

Make sure that the following routing keys are not empty. If another value is specified, leave it as is.

rabbitmq-success: success rabbitmq-failure: failure rabbitmq-reports: reports

Install mqresults

Download mqresults for Linux using the browser from https://postmastery.egnyte.com/dl/Wb3ib8rbh9.

Copy mqresults to /usr/local/sbin on the server. Remove any extension and make it executable:

chmod +x /usr/local/sbin/mqresults

Run mqresults on the server to test the binary and show all command line parameters:

mqresults -help

Set the rabbitmq-address parameter to the same URI as configured in the MailerQ configuration. The endpoint-url and authorization parameters are provided by Postmastery.

Default exchange

When the default exchange is used it is assumed that the results queue has been configured in MailerQ for exclusive use by the mqresults agent.

Run mqresults with the proper URI and key to test the connection to RabbitMQ:

mqresults -rabbitmq-address="amqp://guest:guest@localhost" \ -endpoint-url="https://hostname/your/endpoint" -authorization="your_access_key"

Wait until "Posted ... events ..." or "No messages yet" is logged. Press Ctrl+C to quit the application.

Named exchange

When a named exchange is used additional parameters are needed to pass the exchange name and the routing keys as configured in MailerQ. The rabbitmq-xxxx parameters should match the settings in the MailerQ configuration.

mqresults -rabbitmq-address="amqp://guest:guest@localhost" \ -queue="console" -rabbitmq-exchange="mailerq" \ -rabbitmq-success="success" -rabbitmq-failure="failure" \ -rabbitmq-retries="retries" -rabbitmq-reports="reports" \ -endpoint-url="https://hostname/your/endpoint" -authorization="your_access_key"

Run mqresults once from the command line with the proper parameters to test it. Wait until "Posted ... events ..." or "No messages yet" is logged. Press Ctrl+C to quit the application.

Run as service

Ubuntu LTS 12-14 or RHEL/CentOS 6

Create an upstart script as /etc/init/mqresults.conf:   

description "Upstart configuration for mqresults" start on filesystem or runlevel [2345] stop on shutdown exec /usr/local/sbin/mqresults -rabbitmq-address="amqp://guest:guest@localhost" -endpoint-url="https://hostname/path/to/endpoint" -authorization="your_access_key" respawn

Reload Upstart configurations:

    initctl reload-configuration

Start mqresults as daemon:

    initctl start mqresults

Ubuntu LTS 16+ or RHEL/CentOS 7

Create systemd configuration as /lib/systemd/system/mqresults.service:

[Unit] Description=Systemd configuration for mqresults [Service] ExecStart=/usr/local/sbin/mqresults -rabbitmq-address="amqp://guest:guest@localhost" -endpoint-url="https://hostname/path/to/endpoint" -authorization="your_access_key" Restart=on-failure [Install] WantedBy=multi-user.target

Start mqresults:

    systemctl start mqresults

View mqresults logging:

    sudo journalctl -u mqresults