问题描述
在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应用程序的交互 Celery-Java ,因为它提供了一个很好的示例,说明了如何从python端进行请求.
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响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!