我将RabbitMQ用作消息经纪和芹菜作为任务队列来处理我的队列内容。让我们以一个基本示例,要添加两个数字x和y。
我已经创建了共享任务为:
tasks.py
from celery import shared_task
@shared_task
def add(x, y):
return x + y
我看到我将内容推到队列时,将数据存储为
,
(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-02:/etc/myproject# python manage.py shell
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myproject.tasks import add
>>> add.delay(5, 5)
<AsyncResult: 88f4d5c2-f68a-42c1-acda-d64593df1899>
但我希望我的数据以不同的格式存储,例如
{operation : 'add', listOfNumbers : [5, 5]}
如何更改方式,我的数据实际上被推入队列?在获取相同的同时,我可以得到字典并解开值并处理相同的处理
I am using RabbitMQ as message broker and Celery as task queue to process my queue content. Lets take a basic example where we want to add two numbers x and y.
I have created the shared task as :
tasks.py
from celery import shared_task
@shared_task
def add(x, y):
return x + y
I see when I am pushing the content to the queue, the data is stored as
![[[5, 5], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]](https://i.sstatic.net/fNbbt.png)
(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-02:/etc/myproject# python manage.py shell
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myproject.tasks import add
>>> add.delay(5, 5)
<AsyncResult: 88f4d5c2-f68a-42c1-acda-d64593df1899>
But instead I would like my data to be stored in a different format like
{operation : 'add', listOfNumbers : [5, 5]}
How can I change the way in which my data is actually getting pushed into the queue? While fetching the same I can get the dictionary and unpack the values and process the same
发布评论
评论(1)