Kafka-introduction-enterprise-level messaging system

Why do I need a message system/message queue/message middleware

  • With the development of the website, there are more and more users, and the business is becoming more and more complex, often facing 高并发problems
  • If a large number of users come to access the database at the same time, 如果没有缓冲机制,那么会导致数据库压力过大,连接溢出
  • At this time, some mechanisms are needed to ensure the normal operation of the system, such as the previously learned cache, which blocks the query request before the database, but the modification and update operation is still unstoppable, so a message buffer queue is needed to solve it.
    Insert picture description here

The role of message queues/application scenarios

  • Application 解耦:
    • Multiple applications can process messages through the message queue, and the applications are independent of each other and do not affect each other;
    • As shown in the example below, after the picture is uploaded, the user can respond to the success of the upload immediately, and then the face recognition system will recognize the picture and return the recognition result, or let the user体验更好
    • For example, send 短信验证码, one click to send, and immediately respond to "verification code sent", but in fact, you can put the sending request in the message queue, and then call the operator interface to send the SMS, and put the content in redis for verification/time limit, etc. It can also make the user experience good
      Insert picture description here

Asynchronous processing:

  • Compared to the serial and parallel processing 异步处理可以减少处理的时间;
  • Such as:
    • When the user registers,
    • If you didn’t use the message queue before, it was the same Insert picture description here
      process. Click on the registration button, and you want to send a text message/email/send a welcome letter on the site...a series of operations have a long wait time
    • Now that the message queue is used, it can be processed asynchronously. Click the registration button and return to success directly, and then asynchronously and parallelly process, send text messages/emails/send welcome letters at the same time...

Traffic peak cut/data current limit:

  • Can pass during peak traffic period 消息队列来控制流量, 避免流量过大而引起应用系统崩溃;
  • The message queue also has a good peak shaving effect. Through asynchronous requests, the 将短时间高并发产生的事务消息存储在消息队列中,从而削平高峰期的并发事务reasonable use of message queues in e-commerce website promotions and spike activities can effectively resist the impact of the influx of orders on the system at the beginning of promotional activities.
    Insert picture description here

Information communication:

  • Realize point-to-point message queues or chat rooms, etc.
    Insert picture description here

Pattern classification of message system/message queue

  • Point to point: one to one
  • Publish and subscribe
    Insert picture description here

What are the common messaging systems

  • note:
    • RocketMQ is a message middleware open sourced by Alibaba. The bottom layer refers to Kafka and made some improvements.
    • But Kafka is more mature than RocketMQ, so Kafka is the most used in the big data field.
      Insert picture description here

Guess you like

Origin blog.csdn.net/qq_46893497/article/details/114177318