41 lines
1.1 KiB
Markdown
41 lines
1.1 KiB
Markdown
# Rabbit Worker (Go)
|
|
|
|
Consumes CRUD messages from RabbitMQ and writes to Postgres.
|
|
|
|
## Environment variables
|
|
|
|
RabbitMQ:
|
|
- `AMQP_URL` (preferred), example: `amqp://user:pass@host:5672/vhost`
|
|
- or `RABBIT_HOST`, `RABBIT_PORT` (default 5672), `RABBIT_USER`, `RABBIT_PASSWORD`, `RABBIT_VHOST` (default `/`)
|
|
- `RABBIT_QUEUES` (comma-separated, default `crud_queue`)
|
|
- `RABBIT_DURABLE` (default `true`)
|
|
- `RABBIT_PREFETCH` (default `1`)
|
|
- `REQUEUE_ON_ERROR` (default `true`)
|
|
|
|
Postgres:
|
|
- `DATABASE_URL` (preferred)
|
|
- or `PGHOST`, `PGPORT` (default 5432), `PGUSER`, `PGPASSWORD`, `PGDATABASE` (default `postgres`), `PGSSLMODE` (default `require`)
|
|
- `PG_TABLE` (default `nubes_test_table`)
|
|
|
|
## Message format
|
|
|
|
JSON payload:
|
|
```json
|
|
{"action":"create","text":"hello","id":1}
|
|
```
|
|
|
|
Fields:
|
|
- `action`: `create` | `update` | `delete`
|
|
- `id`: required for `update` and `delete`
|
|
- `text`: used by `create` and `update`
|
|
|
|
If the payload is not JSON, it is treated as `create` with body as text.
|
|
|
|
## Build
|
|
|
|
```bash
|
|
cd /home/naeel/terraform/PROD_STAND/RABBIT/rabbit-worker
|
|
|
|
docker build -t <registry>/<image>:<tag> .
|
|
```
|