Message Queue easy to understand summary

First, what MQ that?
1, MQ message queue called the Message Queue (the MQ), one kind of FIFO data structure, an application communication method of the application. MQ consumption - a model representative of typical producer, end to continue to write messages in the message queue, and the other end of the queue message can be read. Post Owner shoved the messages posted to the MQ without tubes who will take the message users simply take a message from the MQ regardless of who posted. Such publishers and users do not know about each other.
2, RocketMQ as a distributed messaging middleware, experienced a baptism of two-eleven Taobao, and far more functionality and performance in ActiveMQ
3, you can think of a scenario in life: when you put the letters dropped mailbox, postman certainly will eventually letter sent to the recipient. We can MQ likened to the post office and the postman. MQ and the post office is the main thing in common: it does not process the message, however, it will accept the data, stored message data, forward messages

 

 Two, MQ What are the characteristics.
Mainly around three points: decoupling, asynchronous, clipping.
1. Decoupling:
call follows the traditional model

 

 The higher coupling degree, the lower the fault tolerance. With electricity suppliers, for example, after a user to create an order, call if coupled inventory systems, logistics systems, payment systems, a subsystem failure or any other reasons to upgrade temporarily unavailable, can cause abnormal operation orders, affecting the user experience.

 

 

Decoupling using message queues, system fault tolerance will be high. Logistics system fails example, take a few minutes to fix, during this time, the system data stream to be processed into the message queue buffer, the user orders completed normally. When the logistics system back online, the message data to supplement the processing queue exists, the terminal system fault minutes imperceptible logistics system occurred.

2, asynchronous:
the traditional call mode:

 

 

在某场景下,A系统收到一条数据后需要在自己本地写库,同时还要在BCD三个系统写库,自己本地写库要 3ms,BCD 三个系统分别写库要 300ms、450ms、200ms。总共要延时3 + 300 + 450 + 200 = 953ms,接近 1s啊,对强迫症的人来说简直要爆炸!

使用MQ之后:

 

 

如果使用 MQ,那么 A 系统连续发送 3 条消息到 MQ 队列中,假如耗时 5ms,A 系统从接受一个请求到返回响应给用户,总时长是 3 + 5 = 8ms,对于用户而言,其实感觉上就是点个按钮,8ms 以后就直接返回了,那就比原来传统模式同步调用快了。

3、流量肖锋:

 

 

A系统如果遇到请求流量瞬间猛增,有可能会将系统压垮。有了消息队列可以将请求缓存起来,分散到很长的一段时间处理,这样可以大大提高系统的稳定性和用户体验。

 

 

 

一般情况下,为了保证系统的稳定性,如果系统负载超过阈值,就会阻止用户请求,这会影响用户体验,而如果使用消息队列将用户请求缓存起来,等待系统处理完毕后通知用户下单完毕,这样比不能下单体验要好。

三、MQ的缺点。
1、系统可用性降低。
系统引入的外部依赖越多,越容易挂掉。本来你就是 A 系统调用 BCD 三个系统的接口就好了, ABCD 四个系统好好的,没啥问题。但是你偏偏要在系统A和BCD之间加个MQ,好了,MQ一挂,整套系统就蹦,A就调不到BCD了。
2、增加了系统的复杂度。
硬生生加个MQ进来,怎么保证消息没有重复消费?消息丢失的情况?消息的传输顺序性?问题一大堆,都得一一的去处理。

 

Guess you like

Origin www.cnblogs.com/weijianyi/p/12400993.html