๐Ÿš€ AMQP Sidecar

Elixir RabbitMQ Kubernetes Docker

AMQP Sidecar is a lightweight, configurable Elixir application designed to act as a sidecar for consuming and publishing messages via AMQP (e.g., RabbitMQ). It integrates seamlessly with Kubernetes and supports dynamic configuration for exchanges, queues, and routing keys.


๐ŸŒŸ Features


๐Ÿ› ๏ธ Installation

Prerequisites

Steps

  1. Clone the repository:

    git clone https://github.com/alesima/amqp_sidecar.git
    cd amqp_sidecar
  2. Install dependencies:

    mix deps.get
  3. Configure the application:

    • Copy the example config and edit it:
      cp config/broker.json.example config/broker.json
      (or mount it as a ConfigMap โ€” see Kubernetes below).
    • Example broker.json:
      {
        "rules": [
          {
            "exchange": "test_exchange",
            "exchangeType": "topic",
            "queue": "test_queue",
            "routingKeys": ["test.*"],
            "endpointUri": "http://test-endpoint"
          }
        ]
      }

    Supported exchangeType values: topic (default), direct, fanout, x-delayed-message (requires exchangeArguments: {"x-delayed-type": "<type>"}). Messages are matched by exchange plus AMQP topic patterns (* = one word, # = zero or more words). Unmatched messages are acknowledged and dropped with a warning; failed forwards are rejected with requeue.

  4. Run the application:

    mix run --no-halt

๐Ÿšฆ Usage

Consuming Messages

The sidecar automatically consumes messages from the configured exchanges and queues. Messages are forwarded to the specified endpointUri.

Publishing Messages

Use the HTTP API to publish messages:

curl -X POST http://localhost:4000/publish \
  -H "Content-Type: application/json" \
  -d '{
    "exchange": "test_exchange",
    "routingKey": "test.key",
    "message": "Hello, world!",
    "headers": {
      "x-delay": 5000
    }
  }'

Health Check

Check the health of the sidecar:

curl http://localhost:4000/health

๐Ÿณ Running in Kubernetes

  1. Build the Docker image:

    docker build -t amqp_sidecar:latest .
  2. Deploy to Kubernetes:

    • Create a ConfigMap for broker.json:
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: amqp-sidecar-config
      data:
        broker.json: |
          {
            "rules": [
              {
                "exchange": "test_exchange",
                "exchangeType": "topic",
                "queue": "test_queue",
                "routingKeys": ["test.*"],
                "endpointUri": "http://test-endpoint"
              }
            ]
          }
    • Deploy the sidecar:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: amqp-sidecar
      spec:
        replicas: 1
        template:
          spec:
            containers:
              - name: amqp-sidecar
                image: amqp_sidecar:latest
                volumeMounts:
                  - name: config-volume
                    mountPath: /app/config
            volumes:
              - name: config-volume
                configMap:
                  name: amqp-sidecar-config

๐Ÿงช Testing

Run the test suite:

mix test

๐Ÿ“‚ Project Structure

amqp_sidecar/
โ”œโ”€โ”€ config/               # Configuration files
โ”œโ”€โ”€ lib/                  # Application code
โ”‚   โ”œโ”€โ”€ amqp_sidecar/     # Core modules
โ”‚   โ”œโ”€โ”€ web/              # HTTP API and routes
โ”œโ”€โ”€ test/                 # Tests
โ”œโ”€โ”€ Dockerfile            # Dockerfile for containerization
โ”œโ”€โ”€ mix.exs               # Project dependencies
โ””โ”€โ”€ README.md             # This file

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.


๐Ÿ™ Acknowledgments


Made with โค๏ธ by Alex Silva