简体   繁体   English

无法理解如何使用 RabbitMQ

[英]Trouble with understanding how RabbitMQ can be used

i'm currently working on a Python web app that needs to implement RabbitMQ.我目前正在开发一个需要实现 RabbitMQ 的 Python web 应用程序。 The app is structured like that:该应用程序的结构如下:

  1. The client connects to a HTTP server客户端连接到 HTTP 服务器

  2. His connexion is send to a message queue that is connected to the main service of my app他的连接被发送到连接到我的应用程序主要服务的消息队列

  3. the main service receive the message and give the user his information主服务接收消息并向用户提供他的信息

I understand how to make work RabbitMq using the documentation and tutorial on the website but I have trouble seeing how can it work with real tasks like displaying a web page or printing a file?我了解如何使用网站上的文档和教程来完成 RabbitMq 工作,但我无法看到它如何处理实际任务,例如显示 web 页面或打印文件? How does my service connected to the message queue will read the message received and say: "oh, i'm gonna display this webpage".我的服务如何连接到消息队列将读取收到的消息并说:“哦,我要显示这个网页”。

Sorry if this is confusing, if you need further explanations on what i'm trying to get, just tell me.抱歉,如果这令人困惑,如果您需要进一步解释我想要得到的东西,请告诉我。

Thanks for reading!谢谢阅读!

RabbitMq can be good to send message to service which can execute long running process - ie download big file, generate complex animation. RabbitMq可以很好地向可以执行长时间运行过程的服务发送消息 - 即下载大文件,生成复杂的 animation。 Web server can't (or shoudn't) execute long running process. Web 服务器不能(或不应该)执行长时间运行的进程。

Web page sends message to RabbitMq (ie. with parameters for long running process) and get unique number. Web 页面向RabbitMq发送消息(即带有长时间运行过程的参数)并获取唯一编号。 When service has free worker then it checks if there is new message in queue, get it (with unique number) and start worker.当服务有空闲工作人员时,它会检查队列中是否有新消息,获取它(具有唯一编号)并启动工作人员。 When worker finish job then service send result to RabbitMQ with the same uniqe number.当工人完成工作时,服务将结果发送到具有相同唯一编号的RabbitMQ

At the same time web page uses JavaScript to run loop which periodically check in RabbitMQ if there is result with this unique number.同时 web 页面使用 JavaScript 运行循环,定期检查RabbitMQ是否有具有此唯一编号的结果。 If there is no result then it may display progressbar , if there is result then it may display this result.如果没有结果则可能会显示progressbar条,如果有结果则可能会显示此结果。


Example: Celery - Distributed Task Queue .示例: Celery - 分布式任务队列

Celery can use RabbitMQ to communicate with Django or Flask . Celery可以使用RabbitMQDjangoFlask通信。
(but it can use other modules ie. Redis ) (但它可以使用其他模块,即Redis

Using Celery with Django . 使用 Celery 和 Django

Flask - Celery Background Tasks Flask - Celery 后台任务


From Celery repo来自Celery 回购

Celery is usually used with a message broker to send and receive messages. 
The RabbitMQ, Redis transports are feature complete, but there's also 
experimental support for a myriad of other solutions, including using 
SQLite for local development.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM