ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

小白写给菜鸟看的Message Queue

2022-01-13 17:02:05  阅读:223  来源: 互联网

标签:post 菜鸟 sms send Queue 队列 mq Message ZeroMQ


function handle_register() {
 add_user();
 send_sms(); // 发送手机短信,耗时5秒
 show("注册成功。");
}
// 缺点:性急的用户还以为注册失败。

function handle_register() {
 add_user();
 // publish把消息放进队列里后立刻返回。另一个程序/进程不断地从消息队列里取消息并处理(发送短信)。
 publish(body='send_sms'); 
 show("注册成功, 请先随便逛逛,过一会您会收到短信");
}

我与消息队列的八年情缘 - 勇哥技术游记 - 博客园

用户界面和心理挺有讲究。A银行给我发短信"尊敬的XXX先生/女士...",再看到B银行"XXX..."我就有点不舒服:-), C银行的"XXX先生"又让我觉得隐私有点泄露,不过转念一想身份证号它都知道。

最开始就一个程序,send_sms是同一个程序里的一个函数function. 为了和sin(), cos()之类区别,有些编程语言把不返回值只事的函数/一段代码叫做过程proceduce. 我们可以把这个叫做Internal Procedure Call.

为了搞清楚程序崩了是谁的责任,可以把send_sms做成一个另外一个程序,两个进程之间通信,Inter Process Communication. 同一个缩写词acronym/abbreviation有不同的意思是IT界的传统,硬件也不例外,如RTL.

进程间通信有很多种方式,从很底层的共享内存到message queue. POSIX (Portable Operating System Interface) is a set of standard operating system interfaces based on the Unix operating system. POSIX Message Queue提供mq_open(), mq_send(), mq_notify()等函数。

最初我们之间调函数,它没有不被调用的自由。现在它独立了,我们只能给它消息。不过它要是不处理的消息话就没啥用。不处理消息是它的责任,不是我们的。我们可以给这个起名Local Procedure Call.

接下来一台服务器不够用,我们的程序和send_sms在不同的服务器上运行,所以可以算是Remote Procedure Call (RPC)的一种。RPC真有,是Sun公司发明的。Local Area Network局域网,广域网是WAN.

大家都需要的功能就应该做成一个工具/库啥的,所以就有了好些家MQ. 我是小白,一个都没有用过。粗略地看资料:

RabbitMQ is the most widely deployed open source message broker. 它是用ErLang语言写的。它的文档好理解,例子多,支持的客户端语言多。
RabbitMQ is a message broker [掮客qián kè]: it accepts and forwards messages. You can think about it as a post office: when you put the mail that you want posting in a post box, you can be sure that the letter carrier will eventually deliver the mail to your recipient. In this analogy, RabbitMQ is a post box, a post office, and a letter carrier. The major difference between RabbitMQ and the post office is that it doesn't deal with paper, instead it accepts, stores, and forwards [转发] binary blobs of data-messages. 其实blob是binary large object的缩写。binary binary?

ZeroMQ号称最快的消息队列系统。C++写的。ZeroMQ具有非中间件模式,你不需要安装和运行消息服务器或中间件,因为你的应用程序将扮演这个服务器角色。你只需要使用ZeroMQ程序库。听起来像mq_open, mq_send等的多机版。ZeroMQ仅提供非持久性的队列,如果宕机,数据将丢失。也就是说,别的message queue和Redis之类的数据库有点类似或有交集——要存东西。Linux和Windows的文件系统都可以设个notifier,文件变化了时通知/执行你的代码。好像Redis有数据变化了则调用你的功能。

ZeroMQ详解 - 南哥的天下 - 博客园 rabbitMQ、activeMQ、zeroMQ、Kafka、Redis 比较 - 二郎神 - 博客园  开源消息队列:NetMQ - 张善友 - 博客园

操作系统里讲了生产者消费者模型。MQ里的发布订阅好像更复杂,比如发布一条消息激活3个订阅者。GoF的设计模式里好像没讲MQ,但我记得有发布和订阅。

电信业里ErLang还有这个意思:An Erlang is a unit of telecommunications traffic measurement. Strictly, an Erlang represents the continuous use of one voice path. In practice, it is used to describe the total traffic volume of one hour.

Agner Krarup Erlang was born in 1878 in Lønborg, Denmark. He was a pioneer in the study of telecommunications traffic and, through his studies, proposed a formula to calculate the fraction of callers served by a village exchange that would have to wait when attempting to place a call to someone outside the village. In 1909, he published his first work: The Theory of Probabilities and Telephone Conversations.

六级/考研单词: sinister, abbreviation, deploy, broker, carrier, analogy, differentiate, telecommunications, strict, perpetual, pioneer, fraction, converse

标签:post,菜鸟,sms,send,Queue,队列,mq,Message,ZeroMQ
来源: https://www.cnblogs.com/funwithwords/p/15798375.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有