我试图使用docker-compose服务让Flask,Celery和RabbitMQ工作。我能够正常运行,但Celery客户端无法连接到RabbitMQ服务器。在芹菜服务器启动时,我收到此消息:
[2017-02-27 17:52:17,466: ERROR/MainProcess] consumer: Cannot connect to amqp://radmin:**@174.138.76.93:5672//: [Errno 104] Connection reset by peer.
Trying again in 2.00 seconds...
[2017-02-27 17:52:19,481: ERROR/MainProcess] consumer: Cannot connect to amqp://radmin:**@174.138.76.93:5672//: Socket closed.
Trying again in 4.00 seconds...
我的项目文件夹结构是:
├── docker-compose.yml
├── order
│ ├── Dockerfile
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ │ └── __init__.cpython-35.pyc
│ ├── requirements.txt
│ ├── main.py
├── celery
│ ├── Dockerfile
│ ├── __init__.py
│ ├── requirements.txt
│ └── tasks.py
├── proxy
│ ├── Dockerfile
│ └── order.conf
订单文件夹是主烧瓶服务器的位置,芹菜有芹菜任务所在的文件夹。我正在创建一个单独的芹菜工作者,其中由main.py通过
提交的任务 task = celery.send_task('mytasks.outputservice', args=[arg1, arg2])
task.py @app.task(name='mytasks.outputservice')
会收到
我已经在本地实现了它并且它工作正常(远程芹菜任务的事情),我想问题是与RabbitMQ和Celery连接。
我的docker-compose文件是:
version: '2.1'
services:
# Application
ordermanagement:
restart: always
build: ./ordermanagement
expose:
- "8080"
ports:
- "8080:8080"
volumes:
- /usr/src/app/static
depends_on:
- rabbit
- worker
#env_file: .env
#command: /usr/local/bin/gunicorn -w 2 --timeout 90 --keep- alive 90 --bind :8080 scheduledpurchases:app
# RabbitMQ
rabbit:
hostname: rabbit
image: rabbitmq:management
environment:
- RABBITMQ_DEFAULT_USER=radmin
- RABBITMQ_DEFAULT_PASS=radmin
ports:
- "5672:5672" # we forward this port because it's useful for debugging
- "15672:15672" # here, we can access rabbitmq management plugin
# Nginx server
proxy:
restart: always
build: ./proxy
expose:
- "80"
ports:
- "85:80"
depends_on:
- ordermanagement
links:
- ordermanagement:ordermanagement
# Celery worker
worker:
build: ./ordermanagement_celery
user: nobody
depends_on:
- rabbit
我已经看到了与Celery和RabbitMQ相关的其他问题,但大多数问题要么已经解决(ip地址解析),要么是其他一些小问题。
如果有人能就如何解决这个问题给我带头。
PS:我直接从终端部署到DigitalOcean服务器,检查了ip用于RabbitMQ(Celery Broker URL,它与docker-machine ip相同)。