简体   繁体   English

何时使用消息队列以及何时使用云后台工作程序

[英]When to use a message queue and when to use a cloud background-worker

When would I use a message queue like ironMQ and when would i use a job processing worker like ironWorker? 我什么时候会使用像ironMQ这样的消息队列?何时我会使用像ironWorker这样的工作处理工作者?

I have just started researching into these two topics and I am finding it hard to distinguish between the two uses. 我刚刚开始研究这两个主题,我发现很难区分这两个用途。 I understand a worker is more or less a sandbox that will run a program in a different environment outside of the app server to increase the user experience. 我理解一个worker或多或少是一个沙盒,它将在app服务器之外的不同环境中运行程序,以增加用户体验。 I also understand that a message queue is much like its database alternative whereby a task is added to a queue and then another server/programming listens for that task and will then process it. 我也理解消息队列很像它的数据库替代方案,其中任务被添加到队列,然后另一个服务器/编程侦听该任务,然后将处理它。 However, although I think I understand what they are I am having trouble distinguishing when I would use each one and why. 然而,虽然我认为我明白他们是什么,但我无法区分何时使用每一个以及为什么。

If I understand correctly I would use a worker for a task such as image processing. 如果我理解正确,我会使用工作人员完成图像处理等任务。 But then why can't I use a message queue for that and more importantly why not? 但是为什么我不能为此使用消息队列,更重要的是为什么不呢? Surely I could just have an image URL queued in ironMQ and then have another programming retrieve and process it. 当然,我可以在ironMQ中排队一个图像URL,然后再检索并处理它。 In my mind that seems like an extra step so I would avoid that. 在我看来,这似乎是一个额外的步骤,所以我会避免这一点。

A message queue seems fairly pointless to me for common tasks when a worker is available. 当工作人员可用时,对于常见任务,消息队列对我来说似乎毫无意义。 Surely for non-intensive tasks like posting a comment I could have a worker do that? 当然,对于发布评论这样的非密集型任务,我可以让工人这样做吗?

I may have misconceived the difference between each tool and if so please set me straight. 我可能误解了每个工具之间的差异,如果是这样,请让我直截了当。 Otherwise, please help. 否则,请帮忙。

They are very closely related so I can understand the confusion. 它们密切相关,所以我能理解这种混乱。 They are both queue based systems, one being a message queue, one being a task/job queue. 它们都是基于队列的系统,一个是消息队列,一个是任务/作业队列。 Here's a general rule of thumb: 这是一般的经验法则:

  • You'd use IronMQ if you want to run the consumer/worker processes/servers. 如果要运行使用者/工作进程/服务器,则可以使用IronMQ。
  • You'd use IronWorker if you want Iron.io to take care of the consumer/worker processes/servers. 如果您希望Iron.io负责消费者/工作进程/服务器,您可以使用IronWorker。 You also get a bunch of other features/benefits using IronWorker, not just the fact that you don't have to manage your own servers and scale them, etc. 您还可以使用IronWorker获得许多其他功能/优势,而不仅仅是您不必管理自己的服务器并扩展它们等。

So no, you don't need a message queue if you're using IronWorker because IronWorker is your message queue + your processing of that queue. 所以不,如果您使用的是IronWorker,则不需要消息队列,因为IronWorker是您的消息队列+您对该队列的处理。

Not to add any confusion, but some people use IronWorker and IronMQ together too, with workers pulling messages off IronMQ. 不要添加任何混淆,但有些人也一起使用IronWorker和IronMQ,工作人员将消息从IronMQ中删除。 This pattern is good for very short tasks to amortize the setup/teardown of a worker (making database connections or whatever the worker has to do to setup). 这种模式适用于非常短的任务来分摊工作人员的设置/拆卸(建立数据库连接或工人必须做的任何设置)。

Message queue is useful when you want to send some data to other process, part of application, or, even, different application. 当您想要将某些数据发送到其他进程,应用程序的一部分,甚至是不同的应用程序时,消息队列非常有用。 It works like pipe, which transfer data to other side. 它像管道一样工作,将数据传输到另一侧。 For example, I have 10 online shops where customers buy things. 例如,我有10家网上商店,顾客在那里买东西。 I want to process all the checkouts on one server. 我想在一台服务器上处理所有签出。 There are some ways to connect shops to processing center: 有一些方法可以将商店连接到处理中心:

  1. Make API on the checkouts processing center server; 在结帐处理中心服务器上创建API; requires human resources to write API code, API and client on shop side must be failsafe (checkouts must be delivered to processing center). 需要人力资源来编写API代码,商店一侧的API和客户端必须是故障安全的(必须将结账交付给处理中心)。
  2. Put checkouts to DB from shop server, get them on processing server; 将结账退出到商店服务器的DB,将它们放在处理服务器上; it requires access to the same DB from shops and processing center which, sometimes, is not secure enough. 它需要从商店和加工中心访问相同的数据库,有时这种数据库不够安全。 Note, that use of separate DB server must act as message queue. 请注意,使用单独的DB服务器必须充当消息队列。 It must be scalable, so, I need to spend money for infrastructure and administrator. 它必须是可扩展的,因此,我需要为基础架构和管理员花钱。
  3. Send to message queue from shop, get from message queue on other side; 从商店发送到消息队列,从另一边的消息队列中获取; requires message queue service installation and infrastructure support. 需要消息队列服务安装和基础结构支持。

Cloud services, like IronMQ, do infrastructure support, provide simple libraries for many languages, have great web-based UI, etc. 像IronMQ这样的云服务可以提供基础架构支持,为许多语言提供简单的库,具有出色的基于Web的UI等。

The same for IronWorker, etc. systems for asynchronous processing. 用于异步处理的IronWorker等系统也是如此。 For example, if I have small app, I can do such jobs right on my server. 例如,如果我有小应用程序,我可以在我的服务器上做这样的工作。 It only requires to use specialized library. 它只需要使用专门的库。 In case of medium app, I can setup server and install software for asynchronous tasks processing. 在中型应用程序的情况下,我可以设置服务器并安装软件以进行异步任务处理。 If I have huge app with a lot of tasks, it requires to support scalable infrastructure, tasks load balancer, etc. 如果我的应用程序包含大量任务,那么它需要支持可扩展的基础架构,任务负载均衡器等。

Companies which provide cloud services for developers are programmed infrastructure controller layer over services like AWS. 为开发人员提供云服务的公司是通过AWS等服务编程的基础架构控制器层。 They provide easy API to their services, support infrastructure and provide a lot of client libraries for different languages. 它们为其服务提供简单的API,支持基础架构并为不同语言提供大量客户端库。

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

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