One 、 Understand microservice architecture
1、 Microservice technology stack
- The overall framework
Overall learning planning route 2、 The difference between microservice and single architecture
Monomer architecture : Develop all the functions of the business in one project , Deploy as a package
advantage
- Simple structure
- Low deployment cost
shortcoming
- High coupling degree , It is not conducive to construction and development
3、 Distributed architecture : Split the system according to the business function , Each business module is developed as an independent project , Become a service .
advantage :
- Reduce service coupling
- Service expansion is conducive to
shortcoming :
- The architecture is very complex
- Operation and maintenance 、 monitor , Deployment is more difficult
4、 Microservices : It is a distributed architecture scheme with good architecture design
Microservice architecture features :
- Single responsibility : Micro service dishes have smaller grains , Each service corresponds to a unique business capability , Single responsibility , Avoid duplicate business development
- Service oriented : Microservices expose business interfaces
- autonomous : Team independence , Technology independence , Data independence , Deploy independent
- Strong isolation : Isolate service calls 、 Fault tolerance 、 Downgrade 、 Avoid cascading problems
5、 Microservice technology comparison
6、 General enterprise demand comparison
Two 、SpringCloud
1、 Introduce :SpringCloud It is the most widely used microservice framework in China .
SpringCloud It integrates various micro service functional components , And based on SpringBoot The automatic assembly of these components is realized , This provides a good out of the box experience
SpringCloudyuSpringBoot The version compatibility relationship of is as follows :
2、 Service splitting and remote invocation
- Different microservices , The same business cannot be developed repeatedly
- Microservice data independence , Do not access the databases of other microservices
- Microservices can expose their business as interfaces , For other microservices to call
3、 Microservice remote call
- Remote call analysis : Issue in the module http request , Interfaces to access other modules , Realize the call of remote interface
- be based on RestTemplate Sponsored http Request to implement remote call
- http Requesting a remote call is a language independent call , Just know each other's ip, port , Interface path , Request parameters .
// In main class ( Configuration class ) Introduction in springboot With RestTemplate(), Inject spring Containers
// The main class springbootApplication Configuration class
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
restTemplate.getForObject(url,User.class);
According to the requested address ( The request address is the same as the address in the browser ),User.class Can return json The type is converted to the corresponding class ( object );
Providers and consumers of remote calls :
- Service providers : In a business , Services invoked by other microservices .( Provide interfaces to other microservices )
- Serving consumers : In a business , Call the services of other microservices .( Call interfaces of other microservices )
- Intermediate role ( Call other microservices , It is called by other micro Services ): According to business logic , Providing interface and invoking interface are service provider and service consumer respectively
- The roles of providers and consumers are relatively ( Relative to business )
3、 ... and 、Eureka Registry Center
1、 The problem of traditional direct address call
Hard encoding : Write dead address ( How to solve multiple addresses of microservice )
Eureka The role of :
(1)Eureka The registry is divided into two parts :
Consumers choose the corresponding microservices according to load balancing , And make a remote call
The registry has a relationship with the service provider 30 Second heartbeat renewal , Check whether the microservice is still running normally , If it doesn't work properly ,
Just delete it from the registry , And consumers will no longer receive the corresponding information of this micro service , As shown in figure of 8083
The main problem : solve
- How can consumers obtain specific information about service providers ?
- When the service provider starts to Eureka Register your information
- Erueka Save this information
- The consumer sends to... According to the service name Eureka Pull provider information
- If there are multiple service providers , How consumers choose ?
- Consumers use load balancing algorithms , Pick one from the list of services
- How consumers perceive the health status of service providers ?
- The service provider will every 30 Second direction EurekaServer Send heartbeat request , Report health status
- Eureka The record service list information will be updated , Abnormal heartbeat will be eliminated
- Consumers can get the latest information
Eureka The main steps of building :
Eureka Server side :
- introduce eureka-server rely on
<!--eureka Server side -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- Add... To the main class @EnableEurekaServer annotation
- stay application.yml Middle configuration Eureka Address
server:
port: 10086 # Service port
spring:
application:
name: eurekaserver # eureka Service name of
eureka:
client:
service-url: # eureka Address information for
defaultZone: http://127.0.0.1:10086/eureka
Eureka client :
- introduce Eureka-client rely on
<!--eureka Client dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- stay application.yml Middle configuration Eureka Address
spring:
application:
name: user-service # The service name eureka:
client:
service-url: # eureka Address information for ( The client is the same as the server )
defaultZone: http://127.0.0.1:10086/eureka
General service construction process :@LoadBalanced Annotations are used for load balancing
Four 、Ribbon( Load balancing )SpringCloud The components of
- Load balancing principle
- Load balancing strategy
- Lazy loading
Implementation principle of the underlying source code :
technological process :
- Initiate request :RibbonLoadBanlancerClient according to URL Medium id Get the service list dynamically DynamicServerListLoadBalancer Pull the corresponding service list
- After getting the list of services, according to your own strategy IRule( Customizable ), Select a server to return to RibbonLoadBanlancerClient, Re splice the address , Request to the corresponding server
Polling strategy :
Modify load balancing strategy :(server: The server ;service: service )
1、 Code mode , In configuration class , Define a new IRule; After configuration in this way, no matter which service this class accesses, it will follow this rule , The servers assigned are random .
// Here is application( Need the main class of random server ) Configuration class configured in , The load balancing strategy is random
@Bean
public IRule randomRule() {
return new RandomRule();
}
2、 In the configuration file application.yml, Adding a new configuration can also modify the configuration rules ; ( Here you can specify that certain service requests will use this rule , Here is userservice) Represents the class , This service class requests userservice Will follow this rule when , Whatever else .
userservice:
ribbon:
NFLoadBalancerRuleClassName: com.alibaba.cloud.nacos.ribbon.NacosRule # Load balancing rules
Load balancing : Initialize to lazy load , Cache after lazy loading , It will be faster to request access later
( Turn on hunger loading )
If there are multiple designated Services :
A brief introduction to microservice technology stack ,Eureka and Ribbon The introduction and use of more relevant articles
- SpringCloud Learning notes ( Two ): Overview of microservices 、 Microservices and microservice Architecture 、 Advantages and disadvantages of microservices 、 What are the microservice technology stacks 、SpringCloud What is it?
From the perspective of Technology : The core of microservice is to apply traditional one-stop application , According to the business split into one service , thoroughly To decouple , Each microservice provides services of a single business function , A service does one thing , From a technical point of view, it is a small and independent process , class ...
- Microservice technology stack :API Gateway Center , Implementation plan of landing
In this paper, the source code :GitHub· Click here || GitEE· Click here One . Introduction to service gateway 1. Appearance mode The communication between client and each business subsystem must be carried out through a unified appearance object , Facade mode provides a high-level interface , Makes the subsystem easier to use ...
- 【 Special topic on microservice technology 】Netflix Dynamic configuration service - Microservice configuration component chameleon Archaius
Premise introduction If you want to design and develop a microservice infrastructure , Parameterized configuration is a very important point , and Netflix Also open source a chameleon Archaius Configuration center client , and Archaius It can be said that it has more production level features than other clients ...
- be based on .NET CORE Microservice framework -surging Introduction and simple examples of ( Open source )
One . Preface So far, programming development has 11 A year , from VB6.0,ASP Era to ASP.NET Until then MVC, It's a witness to .NET Technology development , From a fearless, ignorant teenager , Now middle-aged uncle , Only I know the ups and downs . With ...
- .NET Core Microservices are based on Steeltoe Use Eureka Realize service registration and discovery
Tip: This article has added .NET Core Microservice Foundation series article index => Steeltoe Directory quick navigation : 1. be based on Steeltoe Use Spring Cloud Eureka 2. be based on Steelt ...
- SpringCloudAlibaba— The concept of microservice and SpringCloudAlibaba Introduce
Catalog 1.1 System architecture evolution 1.1.1 Single application architecture 1.1.2 Vertical application architecture 1.1.3 Distributed architecture 1.1.4 SOA framework 1.1.5 Microservice architecture 1.2 Introduction to microservice Architecture 1.2.1 The common of microservice architecture ...
- SpringBoot Integrate Elastic Stack The latest version (7.14.1) Distributed logging solution , Open source microservice full stack project 【 Youlai mall 】 Log landing practice
One . Preface The importance of logs to a program does not need too much verbal modification , This article will describe the whole stack project of open source microservices in a practical way Youlai mall How to integrate the current mainstream log solutions ELK +Filebeat . Don't talk much , First look at the realization of the renderings ...
- [ Re posting ] Microservice framework Spring Cloud Introduce Part1: Using event and message queuing to implement distributed transactions
Microservice framework Spring Cloud Introduce Part1: Using event and message queuing to implement distributed transactions http://skaka.me/blog/2016/04/21/springcloud1/ APR 21ST, ...
- Discovery and registration of microservices --Eureka
Catalog Service providers . Serving consumers . The relationship among service discovery components Eureka brief introduction Eureka Server Eureka Client To write Eureka Server Register the microservice to Eureka Ser ...
- Spring Cloud Overview of microservice Technology
Spring Cloud It's an ordered set of frames . It USES Spring Boot The convenience of development of distributed system infrastructure simplifies the development of distributed system infrastructure , Such as service discovery registration . Configuration center . The message bus . Load balancing . Circuit breaker . Data monitoring, etc. , all ...
Random recommendation
- Hive in parse_url Use
1.Hive Of parse_url function parse_url(url, partToExtract[, key]) - extracts a part from a URL analysis URL character string ,partTo ...
- javascript Go to textarea Additional content
<html> <body> <textarea id="content"></textarea> <script> va ...
- *【JS】offsetParent
This property will return null on Webkit if the element is hidden (the style.display of this element ...
- date Command to use
date Command help information [[email protected] source]# date --help usage :date [ Options ]... [+ Format ] or :date [-u|--utc|--universal] ...
- quarze How it works
quartz How it works http://lavasoft.blog.51cto.com/62575/181907/ Comparison of several timing tasks http://blog.sina.com.cn/s/blog_69 ...
- Docker actual combat -- Simple deployment nodejs application
How to be in Docker Of container Running in Node.js Program Main idea : A simple Node.js web app, To build a mirror image , And then based on this image , Run a container , To achieve rapid deployment . Operating environment : fictitious ...
- Open source API Testing tools Hitchhiker v0.8 - Automated test results statistics
Hitchhiker It's an open source product that supports multi person collaboration Restful Api Testing tools , Support for automated testing , Data comparison , Pressure test , Support script customization request , Can be easily deployed locally , And yours team Members work together to test Api. ...
- requestAnimationFrame Know how much ?
stay Web Application , There are many ways to achieve animation effect ,JavaScript You can use the timer setTimeout To achieve ,css3 have access to transition and animation To achieve ,html5 in ...
- mysql And redis Performance comparison in various cases
Data table structure CREATE TABLE `jx_goods_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goods_name` varchar(100) ...
- ln -s Soft connection
Create a soft connection ln -s Let's check through examples ls Path discovery for , stay /tmp/ In the catalog /bin/ls Pointing to /usr/bin/ls, So here /tmp/bin/ls What is stored is an absolute path , We can see it as a soft chain ...