AMQP连接由同行重置,但芹菜连接

时间:2016-11-06 18:57:32

标签: python flask rabbitmq celery amqp

我有一个使用Celery和RabbitMQ作为经纪人的烧瓶应用程序。

我已按照此answer中的说明开始使用。

我有两台机器。

运行RabbitMQ的机器A发送要由机器B上的芹菜消耗的任务。

我的经纪人网址和后端结果网址相同:amqp://remote:***@12.345.678.999:5672/remote_host

两台机器上都有烧瓶应用程序的副本。已配置RabbitMQ,以便用户远程授予所有权限"。*。*。*"。 RabbitMQ和Celery之间的所有通信在它们都在机器A上的localhost上运行时工作正常。

我使用celery worker -l info -A app.celery在机器B上启动芹菜,一切看起来都很好:

 -------------- celery@ip-XXX-XX-XX-XXX v4.0.0 (latentcall)
---- **** ----- 
--- * ***  * -- Linux-4.4.0-45-generic-x86_64-with-Ubuntu-16.04-    xenial 2016-11-06 18:18:01
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         app:0x7f5b9dd73d90
- ** ---------- .> transport:   amqp://remote:**@12.345.578.999:5672/remote_host
- ** ---------- .> results:     amqp://
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
            .> celery           exchange=celery(direct) key=celery


[tasks]
  . app.views.task1
  . app.views.task2
  . app.views.task3


[2016-11-06 18:18:01,614: INFO/MainProcess] Connected to amqp://remote:**@12.345.678.999:5672/remote_host
[2016-11-06 18:18:01,627: INFO/MainProcess] mingle: searching for neighbors
[2016-11-06 18:18:02,658: INFO/MainProcess] mingle: all alone
[2016-11-06 18:18:02,672: INFO/MainProcess] celery@ip-XXX-XX-XX-XXX ready.

当我在机器A上运行应用程序并尝试通过RabbitMQ向Celery发送任务时,我得到[Errno 104] Connection reset by peer以下(部分)堆栈跟踪:

  File "/home/ubuntu/app/env/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
self.channel_id, allowed_methods, timeout)
  File "/home/ubuntu/app/env/local/lib/python2.7/site-packages/amqp/connection.py", line 241, in _wait_method
channel, method_sig, args, content = read_timeout(timeout)
  File "/home/ubuntu/app/env/local/lib/python2.7/site-packages/amqp/connection.py", line 330, in read_timeout
return self.method_reader.read_method()
  File "/home/ubuntu/app/env/local/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
raise m
error: [Errno 104] Connection reset by peer

我还得到一个AMQP调试状态网,如下所示:

amqp: DEBUG: Start from server, version: 0.9, properties:    {u'information': u'Licensed under the MPL.  See   http://www.rabbitmq.com/', u'product': u'RabbitMQ', u'copyright':    u'Copyright (C) 2007-2015 Pivotal Software, Inc.', u'capabilities':   

{u'exchange_exchange_bindings': True, u'connection.blocked': True,   u'authentication_failure_close': True, u'basic.nack': True, u'per_consumer_qos': True, u'consumer_priorities': True, u'consumer_cancel_notify': True, u'publisher_confirms': True},

 u'cluster_name': u'rabbit@ip-XXX-XX-XX-XXX.ec2.internal', u'platform': u'Erlang/OTP', u'version': u'3.5.7'}, mechanisms: [u'PLAIN', u'AMQPLAIN'], locales: [u'en_US']

我已经尝试过查看rabbitmqctl list_exchanges,list_consumers,list_bindings,但我还没有多大意义。

我如何调试这个来弄清楚为什么RabbitMQ不能向Celery发送任务?

1 个答案:

答案 0 :(得分:0)

我也有相同的要求,我也遵循了这个tutorial并且它工作正常。

在您的代理网址中看起来像问题,只是尝试按以下方式配置:

from celery import Celery

app = Celery('tasks', backend='amqp',
broker='amqp://username:password@yourIp:5672//')

#Test Celery configuration
@app.task
def test(x, y):
    return x + y

启动工人:

celery worker -l info -A app.celery

测试它:

Python
>>> from app.celery import test
>>> test.delay(3,4)
<AsyncResult: 68480bd4-ebda-4238-87b1-ad896a75a12c>

并检查您的终端,您将获得预期的输出。

注意:我不知道它是否适合您。 我这样做了,它对我来说很好。