"SpringBoot Middleware Design and Practice" Chapter 2 Service Governance, Timeout Fuse

demand background

In a scenario with heavy traffic, for example, after placing an order on an e-commerce platform, the user starts to jump to the online cash register to make payment. Since problems may occur in the payment channel and network environment at any time, how do you ensure the reliability of the payment system?

There are many points to consider to ensure the reliability of the payment system, but the most direct and important content here is the payment response time. If the payment time is too long, the sudden increase in payment requests may bring down the entire service, eventually leading to All services are down.

At this time, you may think of a functional component, timeout and fuse hystrix. This is also a necessary component in most payment systems, but how to use it? Do we add such a functional component to all interfaces? Obviously it is inappropriate to do so. Generally, components like this may be embedded in your It may be on the RPC interface or self-developed gateway, or it may be on the function arrangement of the entire service management layer. In short, it will not be easily exposed to you, allowing you to hard-code it into the business logic implementation.

Then, in this chapter, we will show you the core implementation of component packaging. Remember that any implementation is designed in a way that is most suitable for the current system environment, and does not necessarily have to be rigid in a certain form.

Design

In the face of complex scene problems, there are basically solutions on the market. . Just like the call timeout protection system we need in this chapter, there is a corresponding technical component hystrix, which is a fault-tolerant framework open sourced by Netflix, and is also introduced and used in most RPC services.

Then if we just want to be convenient, simple and don't need to care about how to create and return the result of using such a service, we can wrap the hystrix framework in the middle and shield the call logic. The overall design scheme is shown in Figure 4-1 Timeout fuse middleware framework design.

The general idea is as follows:

Guess you like

Origin blog.csdn.net/weixin_42329623/article/details/130477450