为什么使用消息队列而不是多线程? [英] Why are message queues used insted of mulithreading?

查看:181
本文介绍了为什么使用消息队列而不是多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询,需要有人帮助我.我是消息队列的新手,最近开始查看 Kestrel 消息队列.据我了解,线程和消息队列都用于应用程序中的并发,那么使用消息队列比多线程有什么优势?

I have the following query which i need someone to please help me with.Im new to message queues and have recently started looking at the Kestrel message queue. As i understand,both threads and message queues are used for concurrency in applications so what is the advantage of using message queues over multitreading ?

请帮忙谢谢.

推荐答案

消息队列允许您在程序外进行通信.

message queues allow you to communicate outside your program.

这允许您将生产者与消费者分离.您可以将要完成的工作分散到多个进程和机器上,并且可以相互独立地管理/升级/移动这些程序.

This allows you to decouple your producer from your consumer. You can spread the work to be done over several processes and machines, and you can manage/upgrade/move around those programs independently of each other.

消息队列通常还由一个或多个代理组成,这些代理负责分发您的消息并确保在发生不良事件(例如您的程序崩溃、您升级其中一个程序等)时消息不会丢失.

A message queue also typically consists of one or more brokers that takes care of distributing your messages and making sure the messages are not lost in case something bad happens (e.g. your program crashes, you upgrade one of your programs etc.)

消息队列也可能在程序内部使用,在这种情况下,它通常只是将数据从生产者线程交换/排队到消费者线程以进行异步处理的工具.

Message queues might also be used internally in a program, in which case it's often just a facility to exchange/queue data from a producer thread to a consumer thread to do async processing.

这篇关于为什么使用消息队列而不是多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆