I can not run the celery worker + docker + django. I download image rabbit and linked worker, and at run I get error: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused. worker_1. Django: 1.11, calary: 4.1.0. What doing wrong?
docker-compose
rabbit:
image: rabbitmq:latest
ports:
- "5672:5672"
worker:
build: ./project
volumes:
- ./main:/src/app
depends_on:
- rabbit
links:
- web #django project
entrypoint: /src/app/calery.sh
calery
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app')
app.config_from_object('django.conf:settings', namespace='APP')
app.autodiscover_tasks()
@app.task(bind=True)
def add():
print('Task')
celery.sh
#!/bin/bash
cd app
celery -A app worker -l info
celery-amqp-backend is a rewrite of the Celery's original amqp:// result backend, which was removed from Celery with version 5.0. Celery encourages you to use the newer rpc:// result backend, as it does not create a new result queue for each task and thus is faster in many circumstances.
Celery requires a solution to send and receive messages; usually, this comes in the form of a separate service called a message broker. In celery, the broker is Redis, RabbitMQ, etc who conveying the message between a client and celery.
Understanding Celery & RabbitMQCelery is classified as a Task Queue software and RabbitMQ is classified as a Message Broker.
The error is caused by invalid host for CELERY_BROKER_URL
. Based on the error you provided, it seems that the host in your broker url is 127.0.0.1
, since you are using docker, this will not work unless you provide the public IP of your host. You need to update the host in your CELERY_BROKER_URL
to use the service name in you compose file. In your case it is rabbit
. Something like below should work:
CELERY_BROKER_URL = 'amqp://guest:guest@rabbit:5672/%2F'
Change the user and password and other details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With