I'm replacing some homegrown code with Celery, but having a hard time replicating the current behaviour. My desired behaviour is as follows:
- When creating a new user, a message should be published to the
tasks
exchange with theuser.created
routing key. - Two Celery tasks should be trigged by this message, namely
send_user_activate_email
andcheck_spam
.
I tried implementing this by defining a user_created
task with a ignore_result=True
argument, plus a task for send_user_activate_email
and check_spam
.
In my configuration, I added the following routes and queues definitions. While the message is delivered to the user_created
queue, it is not delivered to the other two queues.
Ideally, the message is only delivery to the send_user_activate_email
and check_spam
queues. When using vanilla RabbitMQ, messages are published to an exchange, to which queues can bind, but Celery seems to deliver a message to a queue directly.
How would I implement the behaviour outlined above in Celery?
CELERY_QUEUES = {
'user_created': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},
'send_user_activate_email': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},
'check_spam': {'binding_key':'user.created', 'exchange': 'tasks', 'exchange_type': 'topic'},
}
CELERY_ROUTES = {
'user_created': {
'queue': 'user_created',
'routing_key': 'user.created',
'exchange': 'tasks',
'exchange_type': 'topic',
},
'send_user_activate_email': {
'queue': 'user_created',
'routing_key': 'user.created',
'exchange': 'tasks',
'exchange_type': 'topic',
},
'check_spam': {
'queue': 'user_created',
'routing_key': 'user.created',
'exchange': 'tasks',
'exchange_type': 'topic',
},
}