芹菜消耗send_task响应 [英] celery consume send_task response

查看:64
本文介绍了芹菜消耗send_task响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django应用程序中,我需要调用在Windows服务器上运行并在其中使用django应用程序在linux服务器上运行的外部应用程序的外部Rabbitmq.

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.

我目前能够通过使用芹菜 send_task 将任务添加到队列中:

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

我的设置如下:

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

由于send_task只返回一个密钥,我不确定如何获取和解析响应?

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

推荐答案

感谢您的理解.因此,由于我想进一步处理答案,因此我使用示例中已经在配置中定义的rpc.

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.

我发现此示例有用,因为大多数python celery示例假定使用者是同一应用程序,它描述了与Java应用程序的交互

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

等待并解析结果.

这篇关于芹菜消耗send_task响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆