Message middleware (1)

1 JMS
Java Message Service, Java Message Service is a message-oriented middleware (MOM) API in the Java platform, used to send messages between two applications or distributed systems for asynchronous communication.

2 mq application scenarios

1) Decoupling
System A is seriously coupled with other messy systems. System A produces a key piece of data, and many systems require system A to send this data. A system should always consider the BCDE four systems if they fail? Do you want to resend or save the message? My hair is gray!

If MQ is used, system A generates a piece of data and sends it to MQ. Which system needs the data to consume it in MQ. If the new system needs data, just consume it directly from MQ; if a system does not need this data, just cancel the consumption of MQ messages. In this way, the A system does not need to consider who to send data to, does not need to maintain this code, and does not need to consider whether the call is successful, failure timeout, etc.

2)
Let's look at another scenario asynchronously . When system A receives a request, it needs to write the library locally, and it also needs to write the library in the three BCD systems. It takes 3ms to write the library locally, and 300ms, 450ms, 200ms. The total delay of the final request is 3 + 300 + 450 + 200 = 953ms, which is close to 1s. The user feels that something is too slow. The user initiates a request through the browser and waits for 1 second, which is almost unacceptable.

Generally, Internet-based companies generally require that each request must be completed within 200 ms for direct user operations, which is almost unaware of users.

If you use MQ, then A system sends 3 messages to the MQ queue continuously. If it takes 5ms, the total time from receiving a request to returning a response to the user is 3 + 5 = 8ms. For the user, it actually feels Just click a button, and it will return directly after 8ms, cool! The website is so well done, so fast!

3) Peak shaving
Every day from 0:00 to 12:00, system A is calm and the number of concurrent requests per second is 50. As a result, every time from 12:00 to 13:00, the number of concurrent requests per second suddenly increases to 5k+. But the system is directly based on MySQL, a large number of requests flood into MySQL, and about 5k SQLs are executed on MySQL every second.

In general, MySQL is almost enough to carry 2k requests per second. If the requests per second reach 5k, MySQL may be killed directly, causing the system to crash and users can no longer use the system.

But once the peak period is over, in the afternoon, it becomes a low peak period. It may be that 1w users are operating on the website at the same time. The number of requests per second may be only 50 requests, which is almost nothing to the entire system. pressure.

If you use MQ, 5k requests are written to MQ per second, and system A can process up to 2k requests per second because MySQL processes up to 2k requests per second. System A slowly pulls requests from MQ, pulling 2k requests per second. Do not exceed the maximum number of requests that it can handle per second. It is ok. In this way, even during peak periods, system A will never Will hang up. While MQ 5k requests come in every second, only 2k requests go out. As a result, during the noon peak period (1 hour), hundreds of thousands or even millions of requests may be backlogged in MQ. This short peak period backlog is ok, because after the peak period, 50 requests enter the MQ every second, but the A system will still process 2k requests per second. Therefore, as long as the peak period is over, the A system will quickly resolve the backlog of messages.

3 Problems caused by MQ
1) Increased system complexity
2) Reduced consistency requirements
4 Middleware for commonly used messages

1 ActiveMQ

ActiveMQ is a powerful open source message bus produced by Apache. It is a message middleware
that fully supports the JMS specification. It provides rich APIs and a variety of cluster construction modes to make it a veteran in the industry.
Message middleware is widely used in small and medium-sized enterprises to
measure MQ. : Service performance, data storage, cluster architecture

Advantages: Rich API
Disadvantages: Its performance cannot keep up with application scenarios such as high concurrency and big data. ActiveMQ seems powerless.
2 Kafka

Kafka is LinkedIn's open source, distributed publish-subscribe messaging system, which currently belongs to Apache's top project. It is characterized by processing message consumption based on the Pull mode, pursuing high throughput, and its design purpose is for log collection and transmission. Version 0.8 starts to support replication, but does not support transactions. There are no strict requirements for message duplication, loss, error, etc., which is suitable for data collection business of Internet services that produce large amounts of data

Advantages: high throughput (millions per second)
Disadvantages: does not support transactions, data reliability is not very high
3 RocketMQ

RocketMQ is Ali's open source messaging middleware, which has been incubated as a top-level Apache project. It is developed in pure Java and has the characteristics of high throughput, high availability and suitable for large-scale distributed system applications. The RocketMQ idea originates from Kafka, which optimizes the reliable transmission and transactional properties of messages. At present, it is widely used in scenarios such as transactions, recharge, stream computing, message push, log streaming, binglog distribution, etc.

Advantages: high performance, support transactions, support for distributed, big data
Disadvantages: maintenance requires professionals, commercial version charges
4 RabbitMQ

RabbitMQ is an open source message queuing system developed using Erlang language and implemented based on the AMQP protocol. The main characteristics of AMQP are message-oriented, queue, routing (including point-to-point and publish/subscribe), reliability, and security. The AMQP protocol is more used in enterprise systems, where data consistency, stability, and reliability are very high, and the requirements for performance and throughput are second.

Advantages: moderate performance, high stability and reliability

Guess you like

Origin blog.csdn.net/cheerlh2018/article/details/107478145