Reputation: 711
I want my email service that I wrote to be completely decoupled from my flask application. I am using celery with rabbitmq. So I am wondering is there a way I can configure celery so that in one project I have the Flask application that sends the message to the queue (producer). And in another project I have the celery instance running that listens to the message and execute the task(consumer). I am still confused by how the communication will exactly work? Do I put the API (that sends the email) in my flask application OR the celery project? Ultimately I would like to have the Flask application and the Celery instance in different EC2 instances - with rabbitmq acting as the message broker.
Thanks for your help!
Upvotes: 11
Views: 5673
Reputation: 10177
You can use Celery's send_task function to send the task through RabbitMQ to the worker using the task name. You still need to import the module that you have the celery app in:
If the task is not registered in the current process you can use send_task() to call the task by name instead.
Example:
from yourmodule.yourapp import celery
celery.send_task("yourtasksmodule.yourtask", args=["Hello World"])
Upvotes: 7