AMQP连接已被对等方重置,但已连接芹菜
我有一个烧瓶应用程序,使用Celery和RabbitMQ作为代理.
I have a flask app using Celery with RabbitMQ as the broker.
我已按照此>中的说明进行操作开始.
我有两台机器.
运行RabbitMQ的机器A发送要由机器B上的芹菜消耗的任务.
Machine A, where RabbitMQ runs, sends tasks to be consumed by celery on Machine B.
我的经纪人网址和后端结果网址相同:amqp://remote:***@12.345.678.999:5672/remote_host
.
My Broker Url and Backend Result Url are the same: amqp://remote:***@12.345.678.999:5672/remote_host
.
两台机器上都具有flask应用程序的副本.已配置RabbitMQ,以便用户远程用户具有.*.*.*"的所有权限.当它们都在计算机A的本地主机上运行时,RabbitMQ和Celery之间的所有通信都可以正常工作.
Both machines have copies of the flask app on them. RabbitMQ has been configured so that user remote has all permissions granted ".* .* .*". All the communication between RabbitMQ and Celery works fine when they're both running on localhost on Machine A.
我用celery worker -l info -A app.celery
在机器B上开始芹菜,一切看起来都很好:
I start celery on Machine B with celery worker -l info -A app.celery
, and everything looks fine:
-------------- 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
:
When I run the app on Machine A and try to send a task through RabbitMQ to Celery, I get [Errno 104] Connection reset by peer
with the following (partial) stack trace:
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调试状态网:
I also get an AMQP debug statemenet like the following:
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,但我对其中的内容并没有多大了解.
I've tried looking at rabbitmqctl list_exchanges, list_consumers, list_bindings, but I haven't been able to make much sense out of them.
如何调试它以弄清为什么RabbitMQ无法将任务发送到Celery?
How can I debug this to figure out why RabbitMQ can't send tasks to Celery?
I also have same requirements, I also followed this tutorial and It's working fine.
看起来像您的经纪人网址中的问题,只需尝试通过以下方式进行配置:
Looks like issue in your broker url, Just try to configure in following way :
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>
并检查您的终端,您将获得预期的输出.
and check your terminal you will get expected output.
注意:我不知道它是否对您有用. 我这样做了,对我来说很好用.
Note: I don't know it will be work for you or not. I did this and it's working fine for me.