让Celery与RabbitMQ一起使用

时间:2017-03-06 18:14:32

标签: python-2.7 rabbitmq celery

我不能让芹菜(版本4.0.2)与RabbitMQ一起使用。我在tasks.py文件中有以下内容(如Celery的tutorial/doc中所示):

from celery import Celery

app = Celery('tasks', broker='pyamqp://guest@localhost//')

@app.task
def add(x, y):
    return x + y

但是当我按下这个命令时:

celery -A tasks worker --loglevel=info

我收到以下奇怪的错误:

Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 22] Invalid argument.

我的RabbitMQ服务器正在运行。这是我按“rabbitmqctl status”命令时得到的结果:

[{pid,188},
 {running_applications,[{rabbit,"RabbitMQ","3.6.6"},
                        {os_mon,"CPO  CXC 138 46","2.2.14"},
                        {rabbit_common,[],"3.6.6"},
                        {mnesia,"MNESIA  CXC 138 12","4.11"},
                        {xmerl,"XML parser","1.3.5"},
                        {ranch,"Socket acceptor pool for TCP protocols.",
                               "1.2.1"},
                        {sasl,"SASL  CXC 138 11","2.3.4"},
                        {stdlib,"ERTS  CXC 138 10","1.19.4"},
                        {kernel,"ERTS  CXC 138 10","2.16.4"}]},
 {os,{unix,linux}},
 {erlang_version,"Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:64] [kernel-poll:true]\n"},
 {memory,[{total,45625464},
          {connection_readers,0},
          {connection_writers,0},
          {connection_channels,0},
          {connection_other,0},
          {queue_procs,2704},
          {queue_slave_procs,0},
          {plugins,0},
          {other_proc,18736352},
          {mnesia,60216},
          {mgmt_db,0},
          {msg_index,51568},
          {other_ets,933528},
          {binary,1069976},
          {code,19343063},
          {atom,711569},
          {other_system,4716488}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,6819561472},
 {disk_free_limit,50000000},
 {disk_free,188958461952},
 {file_descriptors,[{total_limit,1948},
                    {total_used,2},
                    {sockets_limit,1751},
                    {sockets_used,0}]},
 {processes,[{limit,1048576},{used,141}]},
 {run_queue,0},
 {uptime,1138},
 {kernel,{net_ticktime,60}}]

我也使用Python 2.7。 有没有人知道可能出现什么问题?

1 个答案:

答案 0 :(得分:0)

似乎某处有一个错误。我可以通过运行“celery ampq”找到错误的痕迹:

...
File "/usr/local/lib/python2.7/dist-packages/amqp/transport.py", line 194, in <dictcomp>
  opt: sock.getsockopt(SOL_TCP, opt) for opt in TCP_OPTS
File "/usr/lib/python2.7/socket.py", line 224, in meth
  return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument

我已将Celery降级为3.1.23版本,现在可以正常使用了。问题可能来自于我在与Windows 10集成的Ubuntu版本上使用Celery(通常仍然认为它是“真正的”Ubuntu)。