我通过 Celery 将 RabbitMQ 与 Django 一起使用。我正在使用最基本的设置:
# RabbitMQ connection settings
BROKER_HOST = 'localhost'
BROKER_PORT = '5672'
BROKER_USER = 'guest'
BROKER_PASSWORD = 'guest'
BROKER_VHOST = '/'
我导入了一个 Celery 任务并将其排入队列以在一年后运行。从 iPython 外壳:
In [1]: from apps.test_app.tasks import add
In [2]: dt=datetime.datetime(2012, 2, 18, 10, 00)
In [3]: add.apply_async((10, 6), eta=dt)
DEBUG:amqplib:Start from server, version: 8.0, properties: {u'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', u'product': 'RabbitMQ', u'version': '2.2.0', u'copyright': 'Copyright (C) 2007-2010 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.', u'platform': 'Erlang/OTP'}, mechanisms: ['PLAIN', 'AMQPLAIN'], locales: ['en_US']
DEBUG:amqplib:Open OK! known_hosts []
DEBUG:amqplib:using channel_id: 1
DEBUG:amqplib:Channel open
DEBUG:amqplib:Closed channel #1
Out[3]: <AsyncResult: cfc507a1-175f-438e-acea-8c989a120ab3>
RabbitMQ 在 celery 队列中收到这条消息:
$ rabbitmqctl list_queues name messages durable
Listing queues ...
KTMacBook.local.celeryd.pidbox 0 false
celery 1 true
celeryctl_KTMacBook.local 0 true
...done.
然后我通过按 control-C 然后按“a”中止来杀死 RabbitMQ。当我再次启动服务器并使用 rabbitmqctl 检查它时,它说 celery 队列中没有消息:
$ rabbitmqctl list_queues name messages durable
Listing queues ...
celery 0 true
celeryctl_KTMacBook.local 0 true
...done.
芹菜队列很耐用。为什么消息没有持久化?我需要做什么才能使消息持久化?