Rabbit Relay

CLI Reference

Plan, validate, diff topology and operate dead-letter queues from the terminal

Rabbit Relay ships a CLI for reviewing topology in code review and operating dead-letter queues in production.

Connection URL

Commands that contact RabbitMQ resolve the connection URL in this order:

  1. --url <amqp-url> flag
  2. RABBITMQ_URL environment variable
  3. amqp://localhost

Plan

Export the topology your broker would declare, perfect for CI:

npx rabbit-relay plan ./setup.mjs > plan.json

Works with topologyMode: "plan-only" so no setup calls touch the broker.

FlagDescription
--output <file>Write plan JSON to a file instead of stdout

Validate

Check that a plan matches a live broker:

npx rabbit-relay validate plan.json --url amqp://user:pass@localhost:5672
FlagDefaultDescription
--url <url>RABBITMQ_URL or amqp://localhostRabbitMQ connection URL

Exit code: 0 on valid, 1 on blocking issues.

Diff

Compare two plans (local vs production) before merging:

npx rabbit-relay diff plan.json plan.production.json

Output:

# Exchanges only in first plan (new):
+ orders.ex (topic, durable)

# Queues only in second plan (missing):
- orders.q

# Bindings only in first plan (new):
+ orders.q → orders.ex [routingKey: "orders.*"]

Plans are identical.

Dead-letter queue operations

Inspect depth, peek messages (non-destructively), or redrive them back:

npx rabbit-relay dlq inspect orders.dlq --url amqp://localhost

Queue depth and consumer status.

Output (JSON):

{ "queue": "orders.dlq", "messageCount": 42, "consumerCount": 0 }

Add --dry-run to redrive for a no-op count of what would move.

Help

npx rabbit-relay help
npx rabbit-relay dlq help

Exit codes

CodeMeaning
0Success
1Validation failure, missing entity, unexpected error

The dlq redrive command exits with 1 when one or more messages fail.

CI usage

A typical CI pipeline generates a plan from application code, validates it against a staging broker, and compares it with a known production plan:

# 1. Generate the topology plan from the application code
npx rabbit-relay plan ./ci/topology.mjs > plan.json

# 2. Validate against a staging RabbitMQ
npx rabbit-relay validate plan.json --url "$RABBITMQ_URL"

# 3. Compare against the production plan (generated earlier)
npx rabbit-relay diff plan.json plan.production.json

The plan command runs a setup script in plan-only mode. The script must export a default function (or named export setup) that receives a RabbitMQBroker instance:

// ci/topology.mjs
import { RabbitMQBroker } from "@bitspacerlabs/rabbit-relay";

export default function (broker) {
  broker
    .queue("orders.q")
    .exchange("orders.ex", {
      exchangeType: "topic",
      routingKey: "orders.*",
      deadLetter: {
        exchange: "orders.dlx",
        queue: "orders.dlq",
        autoDeclare: true,
      },
    });
}

Generating plans programmatically

You can also build the plan in code and write it to JSON yourself:

import { RabbitMQBroker } from "@bitspacerlabs/rabbit-relay";

const broker = new RabbitMQBroker("ci", {
  topologyMode: "plan-only",
});

await broker
  .queue("orders.q")
  .exchange("orders.ex", {
    exchangeType: "topic",
    routingKey: "orders.*",
  });

console.log(JSON.stringify(broker.planTopology(), null, 2));
PageDescription
Topology PlannerGenerating topology plans
Topology ValidationValidating plans against RabbitMQ
Retry & DLQDLQ config and redrive

On this page