芹菜工作者不消费消息

时间:2016-11-24 16:27:24

标签: django celery

我正在使用带有RabbitMQ的Celery 4.0.0作为django 1.9项目中的消息代理,使用django-celery-results获得结果后端。我是Celery和RabbitMQ的新手。 python版本是2.7.5。

按照Celery文档中有关配置和使用django的celery的说明,并在添加任何实际任务之前,我尝试使用django shell(manage.py shell)调用一个简单的任务,发送芹菜中定义的debug_task文档。

任务发送正常,查看rabbitmq队列,我可以看到新消息已到达正确虚拟主机上的正确队列。 我运行工作器,看起来它启动正常,然后它到达事件循环,什么都不做。不会出现错误,不会出现在worker输出或rabbitmq日志中。

另一方面,同一台机器上的芹菜状态返回没有活动节点。

我可能在这里遗漏了一些东西,但我不知道它可能是什么。

不知道这是否相关,但当我使用'celery purge'清除消息队列时,它会找到该消息并将其清除。

添加到django settings.py中的Celery配置设置:

CELERY_BROKER_URL = 'amqp://user1:passwd1@rabbithost:5672/exp'
CELERY_TIMEZONE = TIME_ZONE    # Using django's TZ
CELERY_TASK_TRACK_STARTED = True
CELERY_RESULT_BACKEND = 'django-db'

django shell中的任务调用:

>>> from project.celery import debug_task
>>> debug_task
<@task: project.celery.debug_task of project:0x23cad10>
>>> r = debug_task.delay()
>>> r
<AsyncResult: 33031998-4cd8-4dfe-8e9d-bda9398525bb>
>>> r.status
u'PENDING'

芹菜工人调用:

% celery -A project worker -l info -Q celery

 -------------- celery@super9 v4.0.0 (latentcall)
---- **** ----- 
--- * ***  * -- Linux-3.10.0-327.4.5.el7.x86_64-x86_64-with-centos-7.2.1511-Core 2016-11-24 18:15:27
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         project:0x25931d0
- ** ---------- .> transport:   amqp://user1:**@rabbithost:5672/exp
- ** ---------- .> results:     
- *** --- * --- .> concurrency: 24 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[tasks]
  . project.celery.debug_task

[2016-11-24 18:15:28,984: INFO/MainProcess] Connected to amqp://user1:**@rabbithost:5672/exp
[2016-11-24 18:15:29,009: INFO/MainProcess] mingle: searching for neighbors
[2016-11-24 18:15:30,035: INFO/MainProcess] mingle: all alone
/dir/project/devel/python/devel-1.9-centos7/lib/python2.7/site-packages/celery/fixups/django.py:202: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2016-11-24 18:15:30,072: WARNING/MainProcess] /dir/project/devel/python/devel-1.9-centos7/lib/python2.7/site-packages/celery/fixups/django.py:202: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2016-11-24 18:15:30,073: INFO/MainProcess] celery@super9 ready.

检查rabbitmq队列:

% rabbitmqctl list_queues -p exp
Listing queues ...
celery  1

工作人员“准备好”时的芹菜状态调用:

% celery -A project status
Error: No nodes replied within time constraint.

感谢。

0 个答案:

没有答案