Spring Cloud
Spring Cloud provides developers with the tools to quickly build common patterns in distributed systems (such as configuration management, service discovery, circuit breakers, intelligent routing, micro-proxies, control buses). The coordination of distributed systems has led to boilerplate patterns, and the use of spring cloud developers can quickly support services and applications that implement these patterns. They will work well in any distributed environment, including developers ' own laptops, bare metal data centers, and hosted platforms such as Cloud Foundry.
features
Spring Cloud is focused on providing a good out-of-the-box experience with typical use cases and extensibility mechanisms covered.
Distributed/versioned Configuration
Service Registration and Discovery
Routing
Service-to-service Call
Load Balancing
Circuit Breaker
Distributed Message Delivery
Springcloud distributed development Five Gods Beast
Service Discovery--netflix Eureka
Customer Support load Balancer--netflix Ribbon
circuit breaker--netflix hystrix
Service Gateway-- Netflix Zuul
Distributed configuration--spring Cloud Config
Create a service registry Eureka ServerHere we need to use the components on spring Cloud Netflix Eureka, Eureka is a service registration and Discovery module.
1: First create a master maven project
2: Create the model in the project created in 1, named Server, as Eureka server
The creation process is as follows
After the creation is complete, pom.xml is as follows
<?XML version= "1.0"encoding= "UTF-8"?> <Project xmlns= "http://maven.apache.org/POM/4.0.0"xmlns:XSI= "Http://www.w3.org/2001/XMLSchema-instance" XSI: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupId>com.springcloud</groupId> <Artifactid>server</Artifactid> <version>0.0.1-snapshot</version> <Packaging>jar</Packaging> <name>server</name> <Description>demo Project for Spring boot</Description> <Parent> <groupId>org.springframework.boot</groupId> <Artifactid>spring-boot-starter-parent</Artifactid> <version>1.5.8.release</version> <RelativePath/> <!--lookup parent from repository to </Parent> <Properties> <project.build.sourceEncoding>utf-8</project.build.sourceEncoding> <project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>edgware.release</spring-cloud.version> </Properties> <Dependencies> <!--Eureka Server--<Dependency> <groupId>org.springframework.cloud</groupId> <Artifactid>spring-cloud-starter-eureka-server</Artifactid> </Dependency> <Dependency> <groupId>org.springframework.boot</groupId> <Artifactid>spring-boot-starter-test</Artifactid> <Scope>test</Scope> </Dependency> </Dependencies> <dependencymanagement> <Dependencies> <Dependency> <groupId>org.springframework.cloud</groupId> <Artifactid>spring-cloud-dependencies</Artifactid> <version>${spring-cloud.version}</version> <type>pom</type> <Scope>import</Scope> </Dependency> </Dependencies> </dependencymanagement> <Build> <Plugins> <plugin> <groupId>org.springframework.boot</groupId> <Artifactid>spring-boot-maven-plugin</Artifactid> </plugin> </Plugins> </Build> </Project>
4. Start the service registry and create the following pom.xml
Only one annotation @enableeurekaserver is required, this annotation needs to be added to the Springboot project's Startup application class
/**
* Start a service registration center
*
wang_ */
@EnableEurekaServer
@SpringBootApplication
serverapplication {
main (string[] args) {
Springapplication.run (serverapplication . class, args);
}
}
5: Modify the configuration file:
#端口号
server.port7080
#
eureka.instance.hostnamelocalhost
# #false来表明自己是一个eureka server
Eureka.client.register-with-eureka=false
# # False to indicate that you are a Eureka server
eureka.client.fetch-registry=false
Eureka.client.service-url.defaultzonehttp://${eureka.instance.hostname}:${ server.port}/eureka/
#关闭springboot自带的ioc
false
6: Start the project, visit http://127.0.0.1:7080/
No service is found because there is no registration service now
Create a service provider Eureka client when the client registers with the server, it provides some metadata, such as the host and port, the URL, the home page, and so on. Eureka server receives heartbeat messages from each client instance. If the heartbeat times out, the instance is typically removed from the registration server.
1: The creation process is approximately the same as the server, POMR after creation:
< name >client</ name > < Description >demo Project for Spring boot</ description > < Parent > < groupId >org.springframework.boot</ groupId > << Strong>artifactid >spring-boot-starter-parent</ artifactid > < Version >1.5.8.release</ version > < relativepath /> <!- -Lookup parent from repository to </ parent > < properties > <
project.build.sourceencoding >utf-8</
project.build.sourceEncoding > <
project.reporting.outputEncoding >utf-8</