Substituição do Redis por RabbitMQ como broker de mensageria do Celery#1413
Substituição do Redis por RabbitMQ como broker de mensageria do Celery#1413
Conversation
- Add RabbitMQ service to local.yml and production.yml docker-compose files - Update service dependencies to include rabbitmq for django, celeryworker, celerybeat - Set CELERY_BROKER_URL to amqp://guest:guest@rabbitmq:5672// in env files - Change CELERY_RESULT_BACKEND to use Redis directly (decoupled from broker) - Remove CELERY_BROKER_URL derivation from REDIS_URL in production entrypoint - Update celery-exporter broker URL to use RabbitMQ - Update start-dev.sh and docs/conf.py broker URLs - Keep Redis for caching, sessions, and result backend Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Este PR migra o broker do Celery de Redis para RabbitMQ (AMQP), mantendo o Redis para cache/sessões e como result backend, para separar responsabilidades e facilitar a operação/escala.
Changes:
- Atualiza a configuração do Django/Celery para desacoplar
CELERY_BROKER_URLdeCELERY_RESULT_BACKEND. - Adiciona serviço
rabbitmqe ajusta dependências/integrações nosdocker-compose(local e produção), incluindocelery-exporter. - Atualiza envs/scripts para apontarem o broker para RabbitMQ.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
config/settings/base.py |
Separa broker (CELERY_BROKER_URL) de result backend (CELERY_RESULT_BACKEND com default Redis). |
local.yml |
Adiciona serviço rabbitmq (management) e inclui como dependência de django/celeryworker/celerybeat. |
production.yml |
Adiciona serviço rabbitmq e atualiza dependências/celery-exporter para AMQP. |
.envs/.local/.django |
Define CELERY_BROKER_URL apontando para RabbitMQ. |
.envs/.production/.django |
Define RABBITMQ_DEFAULT_* e CELERY_BROKER_URL para RabbitMQ. |
compose/production/django/entrypoint |
Remove export automático de CELERY_BROKER_URL a partir de REDIS_URL. |
docs/conf.py |
Define fallback de CELERY_BROKER_URL para permitir django.setup() em builds de docs. |
start-dev.sh |
Ajusta broker do Celery para AMQP no modo USE_DOCKER=no. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| CELERY_BROKER_URL = env("CELERY_BROKER_URL") | ||
| # http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-result_backend | ||
| CELERY_RESULT_BACKEND = CELERY_BROKER_URL | ||
| CELERY_RESULT_BACKEND = env("CELERY_RESULT_BACKEND", default="redis://redis:6379/0") |
| RABBITMQ_DEFAULT_USER=guest | ||
| RABBITMQ_DEFAULT_PASS=guest | ||
|
|
||
| # Celery | ||
| # ------------------------------------------------------------------------------ | ||
| CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672// |
| ports: | ||
| - "5672:5672" | ||
| env_file: | ||
| - ./.envs/.production/.django |
| ports: | ||
| - 9808:9808 | ||
| command: ["--broker-url=redis://redis:6379/0"] | ||
| command: ["--broker-url=amqp://guest:guest@rabbitmq:5672//"] |
| container_name: scielo_core_local_rabbitmq | ||
| ports: | ||
| - "5672:5672" | ||
| - "15672:15672" |
|
|
||
| # Celery | ||
| # ------------------------------------------------------------------------------ | ||
| CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672// |
| export CELERY_BROKER_URL=amqp://guest:guest@$IP:5672// | ||
| export USE_DOCKER=no | ||
| export IPYTHONDIR=/app/.ipython | ||
| export REDIS_URL=redis://$IP:6399/0 |
|
Testado e funcionando como esperado, necessário realizar teste de massa em ambiente com volume de dados. |
gitnnolabs
left a comment
There was a problem hiding this comment.
Localmente foi testado rodando a tarefa hello
| RABBITMQ_DEFAULT_USER=guest | ||
| RABBITMQ_DEFAULT_PASS=guest |
There was a problem hiding this comment.
Usuários de acordo com a review do Copilot
| sys.path.insert(0, os.path.abspath("/app")) | ||
| os.environ["DATABASE_URL"] = "sqlite:///readthedocs.db" | ||
| os.environ["CELERY_BROKER_URL"] = os.getenv("REDIS_URL", "redis://redis:6379") | ||
| os.environ["CELERY_BROKER_URL"] = os.getenv("CELERY_BROKER_URL", "amqp://guest:guest@rabbitmq:5672//") |
There was a problem hiding this comment.
Usuários de acordo com a review do Copilot. Dá para usar as variáveis de ambiente também.
O que esse PR faz?
Substitui o Redis pelo RabbitMQ como broker do Celery. Redis permanece para cache, sessões e result backend.
Broker (RabbitMQ):
rabbitmqadicionado emlocal.yml(com management UI) eproduction.ymlCELERY_BROKER_URL=******rabbitmq:5672//nos arquivos.envsResult backend (Redis):
CELERY_RESULT_BACKENDdesacoplado do broker — agora lêenv("CELERY_RESULT_BACKEND")com defaultredis://redis:6379/0Entrypoint:
export CELERY_BROKER_URL="${REDIS_URL}"— agora vem direto do env fileOnde a revisão poderia começar?
config/settings/base.py(linhas 367–369) — separação de broker vs result backend. Depoislocal.ymleproduction.ymlpara os serviços Docker.Como este poderia ser testado manualmente?
docker-compose -f local.yml up -dhttp://localhost:15672(guest/guest)Algum cenário de contexto que queira dar?
A separação broker ≠ result backend permite escalar e operar cada componente independentemente. RabbitMQ oferece ack nativo, dead-letter queues e roteamento AMQP que Redis não suporta.
Screenshots
N/A — alterações de infraestrutura/configuração.
Quais são tickets relevantes?
Referências
//no final é o vhost padrão/Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.