fsulser
fsulser

Reputation: 904

celery consume send_task response

In django application I need to call an external rabbitmq, running on a windows server and using some application there, where the django app runs on a linux server.

I'm currently able to add a task to the queue by using the celery send_task:

app.send_task('tasks', kwargs=self.get_input(), queue=Queue('queue_async', durable=False))

My settings looks like:

CELERY_BROKER_URL = CELERY_CONFIG['broker_url']
BROKER_TRANSPORT_OPTIONS = {"max_retries": 3, "interval_start": 0, "interval_step": 0.2, "interval_max": 0.5}

CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_DEFAULT_QUEUE = 'celery'
CELERY_TASK_RESULT_EXPIRES = 3600
CELERY_RESULT_BACKEND = 'rpc://'
CELERY_CREATE_MISSING_QUEUES = True

What I'm not sure about is how I can get and parse the response, since the send_task only returns a key?

Upvotes: 0

Views: 2131

Answers (2)

fsulser
fsulser

Reputation: 904

Thanks that helped for the understanding. So since I want to further process the answer I use rpc as already defined in the config I had in the example.

What I found usefull was this example, because most python celery examples assume that the consumer is the same application, that describes the interaction to a Java app Celery-Java since it gives a good example on how to request from python side.

Therefore my implementation is now:

result = app.signature('tasks', kwargs=self.get_input(), queue=Queue('queue_async', durable=False)).delay().get()

which waits and parses the result.

Upvotes: 0

Sowjanya R Bhat
Sowjanya R Bhat

Reputation: 1168

If you want to store results of your task , you could use this parameter result_backend or CELERY_RESULT_BACKEND depending on the version of celery you're using.

Complete list of Configuration options can be found here (search for result_backend on this page) => https://docs.celeryproject.org/en/stable/userguide/configuration.html

Many options are available to store results - SQL DBs , NoSQL DBs, Elasticsearch, Memcache, Redis, etc,etc . Choose as per your project stack.

Upvotes: 1

Related Questions