简体   繁体   中英

celery tasks queue not working with rabbitmq

Celery tasks successfully executing without queues

setup.

BROKER_URL = "amqp://user:pass@localhost:5672/test"
# Celery Data Format
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'

CELERYD_TASK_SOFT_TIME_LIMIT = 60
CELERY_IGNORE_RESULT = True

@app.task
def test(a,b,c):
    print("doing something here...")

command

celery worker -A proj -E -l INFO

The above setup worker is executing successfully.

I have introduced queue to the celery tasks.

added configuration with the previous setup

from kombu.entity import Exchange, Queue

CELERY_QUEUES = (
    Queue('high', Exchange('high'), routing_key='high'),
    Queue('normal', Exchange('normal'), routing_key='normal'),
    Queue('low', Exchange('low'), routing_key='low'),
)

CELERY_DEFAULT_QUEUE = 'normal'
CELERY_DEFAULT_EXCHANGE = 'normal'
CELERY_DEFAULT_ROUTING_KEY = 'normal'

CELERY_ROUTES = {
    'myapp.tasks.test': {'queue': 'high'},
}

command

celery worker -A proj -E -l INFO -n worker.high -Q high

call

 test.delay(1, 2, 3)

When I execute with the queue worker is not running. Did I miss any configuration?

将CELERY_ROUTES更改为CELERY_TASK_ROUTES-在版本4中已更改

First, make sure that connection established in both rabbit & high worker logs.

Then, try to change your CELERY_ROUTES to:

CELERY_ROUTES = {
    'myapp.tasks.test': {
        'exchange': 'high',
        'exchange_type': 'high',
        'routing_key': 'high'
    }
}

or call the task with queue , for example:

test_task = test.signature(args=(1, 2, 3), queue='high', immutable=True)
test_task.apply_async()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM