spring advantage ：
High cohesion , Low coupling ： Keywords are avoided new The coupling problem of , There is no need for explicit reference relation passing , It can be done through configuration
bean factory ： It's a bean factory ,bean Administration
aop Facet programming
Transaction management through configuration
Easy integration with other frameworks
Agent development mode
spring core ：IOC,aop
springboot:“ Convention is greater than configuration ”
No cumbersome configuration , Inheritance convenience
No extra code and xml
simplify maven to configure
Easy to start With built-in serverlet java -jar xx.jar
@SpringBootApplication It will start ： Set of three annotations , The core is @EnableAutoConfiguration
Simplified coding , Independent operation spring
Simplify configuration , It can not be used at all XML configuration file , You only need to configure and automatically java config
Simplify deployment , built-in Servlet, The requirement of running environment is reduced ,java -jar Can be executed
Simplify monitoring , Application monitoring
Simplify the initial construction of the project , Common third party frameworks , All have corresponding components , The construction of the project is simplified
Call relation description ：
Service container startup , load , Run service provider .
When the provider starts , Register your services with the registry .
When the service consumer starts , Subscribe to the registry for your services
The registry returns the service provider address list to the consumer , If there is a change , The registration center will push the change data to consumers through the opportunity long connection .
Service consumer from provider address list , Based on soft load balancing algorithm , Select a provider to call , Failed by call , Select another call .
Service consumers and providers , Accumulate calls and call times in memory , Send statistical data to the monitoring center every minute
Five components :eureka,ribbon,hystix,feign,zuul
eureka It's a registry ,eureka client Register all services to eureka server,eureka
serve It's a registry , There's a registration form in it , The machine and port where all services are located are recorded ,client It can also be reversed from server Pull registry , To know where all the services are
feign The key mechanism is dynamic proxy , Add a @FeignClient annotation , This interface generates a dynamic proxy , The agent will be based on the requestMapping Annotation to construct the service address you want , Request for this address
Ribbon Is load balancing , Select one server per request , Distribute requests evenly to all machines
Zuul Microservice gateway , Can do unified demotion , Certification, etc
Hystrix Fuse , Services can be automatically restored and degraded , Service isolation , Avoid service avalanche
see Url You know what resources to operate , Is it a vehicle or a fence
see Http Method You know what the action is , Yes, add （post） Or delete （delete）
see Http Status Code You know what the results are , It's success （200） Or an internal error （500）
Redis The right way to update
Deleting and then updating is the wrong logic , Dirty data will be generated
Writing process ：
1. Elimination first cache（ Delete cache ）
2. Write again DB（ Update database ）
Reading process ：
1. Read first cache, If data hits hit Return to
2. If the data does not hit miss Then read DB
3. speak DB The data read from the cache
Update database first , Delete cache after （ proposal , Most use scenarios ）, however , Is there no concurrency problem ? no, it isn't , such as , One is read operation , But the cache was not hit , And then get the data from the database , Here comes a write operation , After writing the database , Invalidate cache , then , The previous read operation puts the old data in , therefore , It can cause dirty data .
Redis Memory based high performance key-value database
Database data is periodically transferred through asynchronous operations flush Save on hard disk . Because it's a pure memory operation ,Redis Very good performance , Not only that , There are many data structures that can be supported . single value The maximum of 1GB, No memcached Save only IMB Data for .
advantage ： Read and write fast , Support data type , Support things , Operations are atomic , Atomicity is the execution of all data , Or not all of them ; Can be used for caching , news , Press key Set expiration time , Automatically delete after expiration .
redis It has the characteristics of master-slave replication ,master It's better not to do intellectual work , Includes snapshots and AOF log file , Do not enable memory snapshot for persistence , The master and slave should be in the same LAN .
How to guarantee redis Is hot data
Related knowledge ：redis When the size of the memory dataset rises to a certain size , Will implement data elimination strategy （ Recycling strategy ）.redis provide 6 Data elimination strategies ：
volatile-lru： From a dataset with an expiration time set （server.db[i].expires） Select the least recently used data for elimination
volatile-ttl： From a dataset with an expiration time set （server.db[i].expires） Select the data that is about to be expired
volatile-random： From a dataset with an expiration time set （server.db[i].expires） Data elimination at random in
allkeys-lru： From dataset （server.db[i].dict） Select the least recently used data for elimination
allkeys-random： From dataset （server.db[i].dict） Data elimination at random in
no-enviction（ expel ）： Prohibition of expulsion data