Metadata-Version: 2.4
Name: rmq-healer
Version: 0.4.3
Summary: Abstract, extensible RabbitMQ error-queue remediation tool
Author: grimnexo
License: MIT License
        
        Copyright (c) 2026 grimnexo
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/grimnexo/RMQ-Healer
Project-URL: Repository, https://github.com/grimnexo/RMQ-Healer
Project-URL: Documentation, https://github.com/grimnexo/RMQ-Healer/tree/main/docs
Project-URL: Issues, https://github.com/grimnexo/RMQ-Healer/issues
Keywords: rabbitmq,amqp,dead-letter-queue,message-queue,remediation,operations
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Monitoring
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pika>=1.3
Requires-Dist: pydantic>=2.0
Requires-Dist: pydantic-settings>=2.0
Requires-Dist: PyYAML>=6.0
Requires-Dist: jsonpath-ng>=1.6
Requires-Dist: Jinja2>=3.1
Requires-Dist: click>=8.1
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Requires-Dist: types-pika; extra == "dev"
Provides-Extra: metrics
Requires-Dist: prometheus-client>=0.19; extra == "metrics"
Provides-Extra: tui
Requires-Dist: textual>=0.50; extra == "tui"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/grimnexo/RMQ-Healer/main/assets/img/rmq-healer-gh-banner.png" alt="RMQ Healer" width="100%"/>
</p>

<p align="center">
  <img src="https://raw.githubusercontent.com/grimnexo/RMQ-Healer/main/assets/img/rmq-healer-logo.png" alt="RMQ Healer Logo" width="180"/>
</p>

<p align="center">
  <strong>Abstract, extensible RabbitMQ error-queue remediation.</strong><br/>
  Classify &rarr; remediate &rarr; audit &mdash; fully configurable, no code required for common cases.
</p>

<p align="center">
  <img alt="Python" src="https://img.shields.io/badge/python-3.11%2B-blue?logo=python&logoColor=white"/>
  <img alt="License" src="https://img.shields.io/badge/license-MIT-green"/>
  <img alt="CI" src="https://github.com/grimnexo/RMQ-Healer/actions/workflows/ci.yml/badge.svg"/>
  <img alt="Coverage" src="https://img.shields.io/codecov/c/github/grimnexo/rmq-healer?logo=codecov"/>
  <img alt="PyPI" src="https://img.shields.io/pypi/v/rmq-healer?logo=pypi&logoColor=white"/>
  <img alt="Docker" src="https://img.shields.io/docker/pulls/bshelhimer/rmq-healer?logo=docker"/>
  <img alt="Code style" src="https://img.shields.io/badge/code%20style-ruff-orange?logo=python"/>
</p>

---

## What Is It?

RMQ Healer watches RabbitMQ error queues and **automatically remediates known failure patterns** — classify, remediate, audit — fully configurable, no code required for common cases.

### When you probably don't need this tool

In a well-designed RabbitMQ system, error queues don't accumulate indefinitely. A properly configured setup handles failure natively:

- **Dead-letter exchanges (DLX)** — messages that are rejected, expired, or exceed queue length limits are automatically routed to a designated dead-letter queue
- **Message TTL** — messages that sit too long are expired and dead-lettered rather than silently dropped
- **Consumer retry logic** — consumers catch transient errors, requeue with backoff, and reject permanently after N attempts
- **Dedicated error consumers** — purpose-built services subscribe to error queues and handle known failure modes inline

If you control the system and have the bandwidth to implement these properly, you should — they are the right long-term answer.

### When RMQ Healer is the right tool

RMQ Healer is built for situations where reconfiguring the messaging system is not an option:

- **Legacy processors you can't modify** — the consumer is a vendor library, a third-party service, or a system outside your control
- **No technical bandwidth for a proper fix** — reconfiguring RabbitMQ topology, updating consumers, and testing safely takes time you don't have right now
- **Temporary remediation during migration** — you're moving toward a better architecture but need something working in the meantime
- **Operational recovery** — a bad deployment filled an error queue and you need to safely triage, replay, and audit the affected messages

In all of these cases, RMQ Healer gives you a safe, auditable, externally-configurable remediation layer — without modifying the application that produced the messages.

## Features

Zero-loss processing, declarative YAML rules, a rich built-in action library (`log`, `mutate_json`, `set_headers`, `python_script`, `republish`, `quarantine`, `route_unknown`, `drop`), Python script hooks for arbitrary logic, Prometheus metrics, dry-run with diffs, and an interactive terminal TUI for config editing, rule management, live runs, and queue inspection.

&rarr; [Full feature list](docs/features.md)

---

## Architecture

Classify &rarr; remediate &rarr; audit. Messages are acked **only** after a terminal action succeeds — if anything fails, the message stays in the queue untouched.

```mermaid
flowchart TD
    EQ[("Error Queue")]
    CL["Classifier\n(first match wins)"]
    WF["WorkflowRunner"]
    AU["AuditLogger\n(JSON-lines)"]

    EQ -->|basic_get| CL
    CL -->|matched rule| WF
    CL -->|no match| UQ[("Unknown Queue")]
    WF --> A1["log / set_headers\nmutate_json / python_script"]
    A1 --> T{"Terminal\naction"}
    T -->|republish| RQ[("Repaired Queue")]
    T -->|quarantine| Q[("Quarantine Queue")]
    T -->|route_unknown| UQ
    T -->|drop| DONE["Ack + discard"]
    WF --> AU
    CL --> AU
```

&rarr; [Architecture overview and design decisions](docs/architecture.md)

---

## Installation

### Recommended: isolated CLI install

Use `pipx` when you want the `rmq-healer` command to be available on your shell `PATH` without manually managing a virtual environment.

```bash
python -m pip install --user pipx
python -m pipx ensurepath
pipx install rmq-healer
```

Restart your shell after `pipx ensurepath`, then verify:

```bash
rmq-healer --version
```

### Alternative: install with pip

```bash
python -m pip install rmq-healer
```

If the install succeeds but `rmq-healer` is not found, your Python scripts directory is probably not on `PATH`. Inspect where the command was installed:

```bash
python -m pip show -f rmq-healer
python - <<'PY'
import sysconfig
print(sysconfig.get_path("scripts"))
PY
```

If you use `pyenv`, refresh shims after installation:

```bash
pyenv rehash
```

### Development install

```bash
git clone https://github.com/grimnexo/RMQ-Healer.git
cd RMQ-Healer
python -m pip install -e ".[dev]"
```

---

## Quick Start

```bash
# 1. Set broker URL
export RMQ_URL="amqp://guest:guest@localhost/"

# 2. Generate config interactively
rmq-healer configure --output config/queues.yml

# 3. Validate
rmq-healer validate --config config/queues.yml

# 4. Test a rule against a sample message
rmq-healer test-rule --config config/queues.yml \
  --queue order-service.error --message examples/retry-timeout/sample.json

# 5. Dry-run with mutation diffs — nothing acked or published
rmq-healer dry-run --config config/queues.yml --all --pretty

# 6. Live run
rmq-healer run --config config/queues.yml --all --pretty

# 7. Peek without consuming
rmq-healer peek --config config/queues.yml --queue order-service.error --count 10

# 8. Visualise a workflow as a Mermaid diagram
rmq-healer workflow render --config config/queues.yml --queue order-service.error

# 9. Search audit logs
rmq-healer audit-search --log audit.jsonl --outcome quarantine
```

---

## Example Configuration

```yaml
rabbitmq:
  url: "${RMQ_URL}"
  prefetch: 10

idempotency:
  enabled: true
  max_handler_attempts: 3

queues:
  - name: order-service.error
    enabled: true
    rules_file: rules/order-errors.yml
    repaired_exchange: order.events
    repaired_routing_key: order.retry
    quarantine_exchange: ops.errors
    quarantine_routing_key: order.quarantine
```

```yaml
# rules/order-errors.yml
rules:
  - id: transient_timeout
    match:
      any:
        - body_contains: "ETIMEDOUT"
        - json_path: $.error.code
          equals: "TIMEOUT"
    workflow:
      - action: set_headers
        params:
          headers:
            x-rmq-healer-rule: transient_timeout
      - action: republish
        params:
          exchange: "{{ queue.repaired_exchange }}"
          routing_key: "{{ queue.repaired_routing_key }}"

  - id: missing_customer_id
    match:
      all:
        - json_path: $.customer_id
          equals: null
    workflow:
      - action: python_script
        params:
          script: scripts/lookup_customer.py
          timeout: 30
          output:
            save_as: customer
      - action: mutate_json
        params:
          set:
            "$.customer_id": "{{ customer.id }}"
      - action: republish
        params:
          exchange: "{{ queue.repaired_exchange }}"
          routing_key: "{{ queue.repaired_routing_key }}"
```

See the `examples/` directory for complete, runnable scenarios.

---

## Documentation

| Topic | Guide |
|---|---|
| Installation & setup | [docs/installation.md](docs/installation.md) |
| Configuration reference | [docs/configuration.md](docs/configuration.md) |
| Writing rules | [docs/rules.md](docs/rules.md) |
| Python script actions | [docs/python-scripts.md](docs/python-scripts.md) |
| CLI reference (all commands) | [docs/cli-reference.md](docs/cli-reference.md) |
| Operations guide | [docs/operations.md](docs/operations.md) |
| Docker deployment | [docs/docker.md](docs/docker.md) |
| Interactive TUI | [docs/developer-gui.md](docs/developer-gui.md) |
| Plugin architecture | [docs/plugins.md](docs/plugins.md) |
| Metrics & observability | [docs/metrics.md](docs/metrics.md) |
| Contributing & tooling | [docs/contributing.md](docs/contributing.md) |
| GitHub workflow | [docs/github-workflow.md](docs/github-workflow.md) |
| Troubleshooting | [docs/troubleshooting.md](docs/troubleshooting.md) |

> **[Browse all docs &rarr;](docs/README.md)**

---

## Developers

Quick start for contributors.

```powershell
# Windows
.\developer\scripts\setup.ps1      # start RabbitMQ + seed fixtures
.\developer\scripts\run-test.ps1   # dry-run against local broker
.\developer\scripts\teardown.ps1   # stop
```

```bash
# Linux / macOS
bash developer/scripts/setup.sh
bash developer/scripts/run-test.sh
bash developer/scripts/teardown.sh
```

```bash
# Python (cross-platform)
python developer/scripts/dev_setup.py
python developer/scripts/run_test.py
python developer/scripts/dev_teardown.py
```

&rarr; [Full contributor guide](docs/contributing.md) &nbsp;&middot;&nbsp; [GitHub workflow](docs/github-workflow.md)

---

## License

MIT &mdash; see [LICENSE](LICENSE).
