我不能使用芹菜和WSL打开插座。
请参阅以下信息:
celery -A proj report
的输出:software -> celery:3.1.26.post2 (Cipater) kombu:3.0.37 py:3.6.7
billiard:3.3.0.23 py-amqp:1.4.9
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:disabled
BROKER_URL: 'amqp://guest:********@localhost:5672//'
pip freeze
中的内容。我正在使用pipenv。 Pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "*"
django-allauth = "*"
django-crispy-forms = "*"
django-debug-toolbar = "==1.10."
numpy = "==1.15.3"
colorama = "==0.4.0"
dateparser = "==0.7.0"
django-extensions = "*"
python-binance = "*"
misaka = "*"
django-celery = "*"
celery = "*"
[requires]
python_version = "3.6"
我在WSL:
sudo apt-get install rabbitmq-server
sudo服务Rabbitmq-服务器重新启动
chmod -R 777 ./ ##否则我没有权限
tasks.py:
from celery import Celery
# app = Celery('tasks', broker='amqp://jm-user1:sample@localhost/jm-vhost')
# app = Celery('tasks', broker='amqp://guest@localhost//')
app = Celery('tasks', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
rabbitmqctl状态:
[{pid,1716},
{running_applications,
[{rabbit,"RabbitMQ","3.6.10"},
{ranch,"Socket acceptor pool for TCP protocols.","1.3.0"},
{ssl,"Erlang/OTP SSL application","8.2.3"},
{public_key,"Public key infrastructure","1.5.2"},
{asn1,"The Erlang ASN1 compiler version 5.0.4","5.0.4"},
{rabbit_common,
"Modules shared by rabbitmq-server and rabbitmq-erlang-client",
"3.6.10"},
{xmerl,"XML parser","1.3.16"},
{crypto,"CRYPTO","4.2"},
{os_mon,"CPO CXC 138 46","2.4.4"},
{compiler,"ERTS CXC 138 10","7.1.4"},
{mnesia,"MNESIA CXC 138 12","4.15.3"},
{syntax_tools,"Syntax tools","2.1.4"},
{sasl,"SASL CXC 138 11","3.1.1"},
{stdlib,"ERTS CXC 138 10","3.4.3"},
{kernel,"ERTS CXC 138 10","5.4.1"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:192] [kernel-poll:true]\n"},
{memory,
[{total,55943096},
{connection_readers,0},
{connection_writers,0},
{connection_channels,0},
{connection_other,0},
{queue_procs,2744},
{queue_slave_procs,0},
{plugins,0},
{other_proc,19080304},
{mnesia,65712},
{metrics,184888},
{mgmt_db,0},
{msg_index,42728},
{other_ets,1769840},
{binary,62120},
{code,21390833},
{atom,891849},
{other_system,12634158}]},
{alarms,[]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
{vm_memory_high_watermark,0.4},
{vm_memory_limit,6791299072},
{disk_free_limit,50000000},
{disk_free,100481589248},
{file_descriptors,
[{total_limit,924},{total_used,2},{sockets_limit,829},{sockets_used,0}]},
{processes,[{limit,1048576},{used,165}]},
{run_queue,0},
{uptime,4073},
{kernel,{net_ticktime,60}}]
运行时:celery -A tasks worker --loglevel=info
,我得到以下输出:
-------------- celery@Alvaro-Laptop v3.1.26.post2 (Cipater)
---- **** -----
--- * *** * -- Linux-4.4.0-17763-Microsoft-x86_64-with-Ubuntu-18.04-bionic
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x7fd7952bcf60
- ** ---------- .> transport: amqp://guest:**@localhost:5672//
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 12 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery
[tasks]
. tasks.add
[2019-01-23 08:38:30,538: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.
Trying again in 2.00 seconds...
[2019-01-23 08:38:32,543: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: Socket closed.
Trying again in 4.00 seconds...
如何打开插座以允许通信?
答案 0 :(得分:13)
检查Rabbitmq是否已启动并正在运行。启用管理控制台:
sudo rabbitmq-plugins enable rabbitmq_management
然后使用来宾/来宾身份访问http://localhost:15672
。查找概述页面>端口和上下文。
如果AMQP绑定到IPv6(::),则可能是问题所在。打开rabbitmq服务器配置:
sudo vi /etc/rabbitmq/rabbitmq-env.conf
并注释掉
# By default RabbitMQ will bind to all interfaces, on IPv4 and IPv6 if
# available. Set this if you only want to bind to one network interface or#
# address family.
NODE_IP_ADDRESS=127.0.0.1
然后重新启动服务:
sudo service rabbitmq-server restart
然后再次检查与RabbitMQ的连接
答案 1 :(得分:0)
听起来您尚未安装并启动Rabbitmq。我发现的最简单的方法是使用docker,但是如果您通过遵循these instructions在WSL下使用ubuntu,则可以使用apt-get
将其安装在WSL中。
答案 2 :(得分:0)
我遇到了完全相同的问题,当我遵循Medium上的“ Django,预定的任务和队列(第2部分)”文章时,我也有一个运行的RabbitMQ服务器,但是设置中的CELERY_BROKER_URL是amqp://username:password@192.168.0.38//
,事实证明这是不正确的。我使用此instructions重新配置了RabbitMQ服务器。希望对您有帮助)
答案 3 :(得分:0)
我能够使用Redis而不是Rabbitmq来配置所有内容:
sudo apt-get install redis-server
sudo service redis-server restart
pip install celery
chmod -R 777 ./
在要执行工作程序的任何文件夹上放置task.py文件。
from celery import Celery
app = Celery('tasks', broker='redis://localhost:6379')
@app.task
def add(x, y):
return x + y
然后执行以下操作:
celery -A tasks worker --loglevel=info
套接字现已打开!