[Django]-How to set Celery with TTL so it purges old messages from a queue?

7👍

x-message-ttl is in millisecondsNOT SECONDS.

You want to put something like this in your celery config file:

from kombu import Exchange, Queue

CELERY_QUEUES = [
                     Queue(
                         'celery',
                         Exchange('celery'),
                         routing_key = 'celery',
                         queue_arguments = {
                                                'x-message-ttl': 30000
                                           }
                     )
                ]

2👍

The option CELERY_EVENT_QUEUE_TTL= 30 is only for Events and not for Tasks as the name states. Celery will keep a message for a task as long as necessary, which makes sense.

In my case I used RabbitMQ Federation which doubled the queue. Switching to Shovel solved the issue for me.

👤David

Leave a comment