Async (RabbitMQ)¶
Goal: decouple request vs. execution via messaging and dispatch tasks asynchronously.
- Client → Gateway → Producer persists & publishes (publisher confirm) → immediately return 202 with a task status URL
- Consumer uses manual ack, idempotency via RedisSETNX; failures go to retry (q.1m → q.5m → q.30m), then to DLQ
- InjecttraceIdat every hop to stitch APM / Log / Metrics
1. Queue Monitoring & Async Architecture¶
1.1 Queue Monitoring (Queue)¶
- Watch: ready / unacked / total, bindings (routing key / exchange), DLX/DLQ settings, etc.
- Gateway can set queue depth thresholds to enable a 429 guard (protect the ingress).
1.2 Async Architecture¶
- Producer: return 202 only after publisher confirms; write Redis for
status/progress/result(with TTL). - Exchange/Queue: topic exchange; robot.task.q as work queue, robot.retry for multi-stage retries, finally to DLQ.
- Consumer:
prefetch = N, manual ack; on failure, publish torobot.retry.
2. Integration Design & Key Parameters¶
publisher-confirm-type: correlated&publisher-returns: true,mandatory: trueto make returns observable.- Concurrency:
concurrency=2,max-concurrency=8, prefetch=20 (total in-flight ≈ 40). - TTL:
message-ttl=3600s; task result TTL can be 24h. - No requeue on exceptions:
default-requeue-rejected: falseto avoid “zombie” retries.
3. Consumption & Error Handling¶
- Failure handling: route to
robot.retryfirst (q.1m → q.5m → q.30m); after exhausting retries →robot.task.dlq. - Idempotency: Redis
SETNXontaskIdto ensure exactly-once business execution at the consumer side. - Observability: stitch the chain with
traceIdacross Gateway / Producer / RabbitMQ / Consumer for fast RCA.
4. Integration Results (Postman)¶
- Create Task: returns
202 Accepted+statusUrl. - Query Task: look up Redis (or DB) by
taskId, returns PENDING / RUNNING / SUCCESS / FAIL. - Inject X-Request-Id in headers to align with logs/traces.






