在Docker容器中阻塞Celery task.delay

我在我的Django项目中使用芹菜。 它适用于我的MacBook和CentOS虚拟机。 当我在add.delay容器中运行它时,包含add.delayadd是一个任务)方法的请求始终被阻塞。

我在github上创build了一个演示项目: https : //github.com/fengyouchao/proj_test

我的任务:

 @shared_task def add(x, y): return x + y 

我的看法:

 def index(request): a = int(request.GET.get('a', 1)) b = int(request.GET.get('b', 2)) add.delay(a, b) return HttpResponse("Hello world") def hello(request): return HttpResponse("hello") 

在演示项目中,我在docker-compose.yml中创build了三个服务:

  1. web – 运行“manage.py runserver 0.0.0.0:8000”的服务
  2. 芹菜 – 运行“芹菜”的服务
  3. rabbitmq – 运行rabbitmq-server的服务

运行服务

 docker-compose up 

testing

 curl localhost:8000 # blocked curl localhost:8000/hello # OK 

在当前系统中运行django项目(在Docker容器中使用相同的rabbitmq-server)

 manage.py runserver 0.0.0.0:18000 

testing

 curl localhost:18000 # OK , and the "celery" service printed task logs 

这个问题一直困扰我很久,我不知道问题在哪里。 我希望有一个人可以帮助我。 谢谢!