RABBITMQ:在使用芹菜处理任务时,如何检查队列内容?

发布于 2025-02-06 09:01:38 字数 1405 浏览 2 评论 0原文

我已经在我的Django应用中使用RabbitMQ和芹菜设置了一个基本消息和任务队列。根据我的理解,当我使用延迟Menthod时,将我的任务推到Rabbitmq队列,而我的芹菜应用程序中的一名工人从队列中获取相同的操作来执行相同的操作。 有什么方法是,当我使用延迟将任务推到队列时,我可以在消息队列Rabbitmq管理门户上查看相同的方法?由于这些任务几乎立即获取并处理了,因此没有机会在门户上查看它们。

这是我尝试的方法,我认为在我的任务方法中添加睡眠计时器是错误的。

sudo nano tasks.py

from __future__ import absolute_import, unicode_literals
from celery import shared_task
import time

@shared_task
def add(x, y):
    time.sleep(100)
    return x + y

启动了我的芹菜应用程序

(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-01:/etc/myproject# celery -A myproject worker -l info

推动了处理的任务

(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-01:/etc/myproject# python3 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 app1.tasks import add
>>> add.delay(1,2)

在芹菜窗口上

[2022-06-10 06:16:15,182: INFO/MainProcess] celery@ubuntu-s-1vcpu-1gb-blr1-01 ready.
[2022-06-10 06:17:38,485: INFO/MainProcess] Task app1.tasks.add[be566921-b320-466c-b406-7a6ed7ab06e7] received

,但我在我的队列中看不到内容

”

I have setup a basic message and task queue using RabbitMQ and Celery in my Django app. According to my understanding the when I use delay menthod, that pushes my tasks to the rabbitMQ queue and one of my workers from my celery app fetches the same from queue to execute the same.
Is there any way in which when I push the task to the queue using delay I can view the same on my message queue RabbitMQ management portal? Since the tasks are almost instantly fetched and processed there is no chance of viewing them on the portal.

This is what I tried which I think is wrong by adding a sleep timer in my task method.

sudo nano tasks.py

from __future__ import absolute_import, unicode_literals
from celery import shared_task
import time

@shared_task
def add(x, y):
    time.sleep(100)
    return x + y

Started my celery app

(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-01:/etc/myproject# celery -A myproject worker -l info

Pushed the tasks for processing

(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-01:/etc/myproject# python3 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 app1.tasks import add
>>> add.delay(1,2)

On celery window

[2022-06-10 06:16:15,182: INFO/MainProcess] celery@ubuntu-s-1vcpu-1gb-blr1-01 ready.
[2022-06-10 06:17:38,485: INFO/MainProcess] Task app1.tasks.add[be566921-b320-466c-b406-7a6ed7ab06e7] received

But I don't see the content in my queue

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

困倦 2025-02-13 09:01:38

免责声明:我不确定这种方式多么完美 - 但是,它将完成工作。


  • 步骤1 :关闭工人(即杀死/终止由celery -a myproject Worker命令引发的过程)
  • 步骤2 :按消息到RabbitMQ(只需使用.delay()方法从Django Shell调用任务)
  • 步骤3 :检查RabbitMQ Management Console。

注意:您可以消耗/查看/弹出队列中的消息。根据您选择的流行机制(acknack - (如果我错了,请纠正我)),工人将能够在消息实时后消耗。

Disclaimer: I'm not sure how perfect this way is - But, it will do the job.


  • Step 1: Turn off the worker (that is kill/terminate the process initiated by celery -A myproject worker command)
  • Step 2: Push the messages into RabbitMQ (Just call the task from Django shell with .delay() method)
  • Step 3: Check the RabbitMQ management console.

Note: You can consume/view/pop the messages from the queue. Depending on the pop mechanism you choose (ack or nack -(correct me if I'm wrong)), the worker will be able to consume the messages once it's live.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文