day3-SpringCloud microservice

 

1 SpringCloud

The simplest logic to use: write entity classes, call mapper, write Service layer, and finally write external interface

2 Nginx

Function: Reverse proxy, use a server to proxy the real server. When the user visits, it is no longer to visit the real server, but the proxy server.

3 Eureka

Role: Solve service management problems

4 Robbin

Role: Solve service access problems and achieve load balancing

5 Feign 

Function: Feign can hide the request of Rest, disguising it as a Controller similar to SpringMVC. You don’t need to splice URLs, splicing parameters and so on by yourself, just leave everything to Feign to do

Using Robbin, there is a lot of duplicate code, the format is basically the same, Feign can align and optimize

6 Hystrix (there will be integration in Feign)

Use Fallback's fusion mechanism to avoid the spread of faults caused by exceptions in individual services in the microservice architecture

7 Zuul

As one of the important functions of the gateway, it is to realize the authentication of the request. And this action is often achieved through filters provided by Zuul.

(Zuul has integrated Ribbon load balancing and Hystix fuse mechanism by default)

Why use Zuul?

In this architecture, our service cluster includes: internal services Service A and Service B. They both register and subscribe to the Eureka Server. Open Service is an external service that is exposed to the service caller through load balancing. We focus on external services and directly expose our service address. Is this implementation reasonable, or is there a better way to implement it?

 

Let me talk about some of the things that need to be done and the shortcomings of this architecture:

 

First, it destroys the stateless nature of the service.

In order to ensure the security of external services, we need to implement permission control over service access, and the permission control mechanism of open services will penetrate and pollute the business logic of the entire open service. The most direct problem that this will bring is that it destroys the service. The stateless feature of the REST API in the cluster.

From the perspective of specific development and testing, in addition to the actual business logic, you also need to consider the control of interface access.

Secondly, existing interfaces cannot be reused directly.

When we need to access an existing cluster access interface to achieve external service access, we have to add verification logic to the original interface, or add a proxy call to achieve permission control, and cannot directly reuse the original interface .

 

Stateless Service:

It means that the instance of the service running will not store the data that needs to be persisted locally, and the results of multiple instances for the same request response are exactly the same

 

Stateful Service:

It means that the instance of the service can back up part of the data at any time, and when a new stateful service is created, the data can be restored through the backup to achieve the purpose of data persistence.

 

 

8 Hook

Reference link: https://zhuanlan.zhihu.com/p/86534217

1. What is Hook technology

  Hook technology is also called hook function. Before the system calls the function, the hook program captures the message first, and the hook function gets the control right. At this time, the hook function can process (change) the execution behavior of the function, or force it. End the delivery of the message. To put it simply, it is to pull out the program of the system into code fragments that we execute ourselves.

  To implement the hook function, there are two steps:

  1. Use the interface provided inside the system to implement the interface and then inject it into the system (used in specific scenarios)

  2. Dynamic proxy (use all scenarios)

 

Second, the steps of Hook technology implementation

  The steps of Hook technology implementation are also divided into two steps

  1. Find the hook point (Java layer), the hook point must meet the following conditions: the method that needs to be hooked, the object to which it belongs must be static, because we get the object through reflection, and what we get is the object of the system. Therefore, a new object cannot be new, and the object created by the system must be used, so only static ones can be guaranteed to be consistent with the objects of the system.

  2. Put the hook method out of the system for execution (put into our own logic)

 

I will understand Hook in a relatively simple way that I think. The function I want to achieve is:

1. Inherit an object that can be inherited, and then rewrite a method to add intermediate processing, such as verification. When you're done, you can use super to call the method of the parent class.

2. Then replace the original variable with this new object variable to realize the dynamic replacement of the object variable

3. The key point is the basic use of Field and Proxy

 

Callback function and hook function

https://blog.csdn.net/lipeionline/article/details/6369657

Regarding the definition:

What is a callback function?

In short, a callback function is a function called through a function pointer . If you pass a function pointer (address) as a parameter to another function, when this pointer is used to call the function it points to, we say that this is a callback function.

Why use a callback function?

Because the caller can be separated from the callee. The caller does not care who is the callee, all it needs to know is that there is a called function with a certain prototype and certain restrictions (such as a return value of int).

What is a hook function?

A hook is actually a program segment that processes messages , which is hooked into the system through system calls. Whenever a specific message is sent, the hook program first captures the message before it reaches the destination window, that is, the hook function first gets the control right.

Guess you like

Origin blog.csdn.net/qq_42198024/article/details/107824432