Karesh A
Karesh A

Reputation: 1751

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?

Upvotes: 0

Views: 2979

Answers (2)

ItayB
ItayB

Reputation: 11337

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()

Upvotes: 0

Karesh A
Karesh A

Reputation: 1751

Change CELERY_ROUTES to CELERY_TASK_ROUTES- changed in version 4

Upvotes: 1

Related Questions