This is Little’s fifth installment of the week, when Spring Boot meets message queues.

Spring Boot version 1.0

Long, long ago, as a single application, there was only one Spring Boot application. When two Spring boots needed to establish a connection, RestFulAPI was used as the connection between the two applications to realize their communication. The specific process is as followsAs shown in the figure above, when there is access, a request is made directly to the API GATEWAY, which then dispatches it to the relevant interface for access. As shown above. It’s pretty smooth for the interface at this point, and the application communicates all through Rest. Do not interfere with each other, do not affect each other, each other quite smooth, years well, all peace.

Message queuing achieves peak clipping

What happens when there’s a lot of traffic coming in, and suddenly you can’t handle that many requests.Request too much, one move to solve, add machine, direct cluster start, a set of cluster, direct take.What the cluster brings, a large number of machines, a large number of manpower, a large number of material resources, a large number of financial costs, are all money ah. Silver hubbub like water general flow away.There are several points

  1. You can do this in peak times, because you earn more, you spend more, you make more, you make more.
  2. You can’t do that in the trough, because it’s all cost, and the peak is only for a moment, so that’s where the message queue comes in.

Message queuing implements peak cutting v2.0

The architecture diagram above continues to evolve. And transformThis here adds the relevant message queue, through the message queue to realize when the traffic comes, plays the role of the dam, temporarily intercept the traffic.

Such an exquisite design, never seen before, never seen after wow.

With such a simple message queue, basic peak peaking of traffic is achieved, saving both cost and server overhead.

Communication between applications v3.0

At this time, the application is decoupled into multiple parts, one part is the user module, the other part is the mail module. For example, when the user is registered successfully, the message is sent to the mail module, so that it can send the mail.

Clipping will not be covered again in this section

The easiest way is to call the API directly.

Through the WAY of API, to achieve direct call, the flow chart is as follows

Here’s the problem!

What if a lot of requests come in! The call failed. Does the sender know that? How do I make sure I only call once, and how do I make repeated calls? Because of the mail processing and user processing module, the performance is inconsistent, how to deal with the huge difference between the two performance.

A multitude of problems need to be solved.

At this point, the message queue continues to appear

The application of message queues

The architecture diagram is as follows

Communication between two applications one producer and one consumer communicate with each other directly through message queues.It was almost so beautifully done, so seamless. It’s incredible.

conclusion

Using message queue, realize the mutual decoupling between two applications, and realize its basic functions such as things. And the function of asynchrony focuses on the decoupling of applications, the basic implementation of things, the basic implementation of asynchrony.

Log processing v4.0

If the application scale is small, you do not need to perform small-scale log processing. In this case, you can save logs locally. If the application scale is large, up to gb of logs are generated every day.

Use message queues for log processing

Two pictures to worship heaven Its core is the producer and consumer model, which is derived from the operating system through the producer………

In simple terms, the amount of logs is too large. The client collects logs and puts them into the message queue for delay processing. Then the log processing application collects logs again. Basic log processing is achieved through ELK.

That is, the ELK component is used to process basic log information.