Reputation: 85
I am trying to develop an application which is composed of a listener which sends events to RabbitMQ, which Celery extracts from a queue.
When running all the components locally my application works as expected. It also works if my listener is running locally, and all the other components are running in Docker containers. But if I also run my listener in a container then Celery does not receive any events.
The application is based on Django and the connection to Celery is done like this:
app = Celery('mini_iot')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
And in settings.py I have:
CELERY_BROKER_URL = 'amqp://rabbitmq'
Where rabbitmq is the hostname of the container.
The listener sends tasks to Celery using the delay
function.
The docker-compose is:
version: '3'
services:
listener:
image: core-app
command: python manage.py runscript listener
volumes:
- .:/mini-iot
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
worker:
image: core-app
command: celery -A mini_iot worker --loglevel=info -f log2.txt
volumes:
- .:/mini-iot
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
rabbitmq:
image: rabbitmq:3.6.10
volumes:
- /var/lib/rabbitmq:/var/lib/rabbitmq
ports:
- "5672:5672"
- "15672:15672"
Can anyone help me debug the problem or does anyone have an idea about what the problem is?
The containers can communicate with each other on the correct ports. I have tested using telnet.
Upvotes: 0
Views: 3856
Reputation: 4161
I think your CELERY_BROKER_URL should be
amqp://guest:guest@rabbitmq:5672
According the the rabbitmq docker docs (https://hub.docker.com/_/rabbitmq/), the default username and password are guest/guest.
Upvotes: 1
Reputation: 11357
you should add links to both listener
& worker
:
version: '3'
services:
listener:
image: core-app
command: python manage.py runscript listener
volumes:
- .:/mini-iot
links:
- rabbitmq
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
worker:
image: core-app
command: celery -A mini_iot worker --loglevel=info -f log2.txt
volumes:
- .:/mini-iot
links:
- rabbitmq
depends_on:
- rabbitmq
- mqtt
working_dir: /mini-iot/mini_iot
rabbitmq:
image: rabbitmq:3.6.10
volumes:
- /var/lib/rabbitmq:/var/lib/rabbitmq
ports:
- "5672:5672"
- "15672:15672"
Upvotes: 0