
五大核心组件如下:
服务发现——Netflix Eureka客户端
负载均衡——Netflix Ribbon
断路器——Netflix Hystrix
服务网关——Netflix Zuul
分布式配置——Spring Cloud Config
一、搭建eureka客户端1.新建一个SpringBoot项目
2.pom文件(springcloud版本需要与springboot版本对应。详情点击)
4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.2 eureka-server eureka-server 1.0-SNAPSHOT eureka-server Eureka Server project for Spring Boot 1.8 2020.0.5 org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-maven-plugin
3.yml文件配置
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
4.启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
5.启动后访问可看到
1.项目pom文件(非全部,对应拷贝)
org.springframework.boot spring-boot-starter-parent 2.4.2 2020.0.5 org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import
2.yml文件
server:
port: 8762
max-http-header-size: 10240
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: xxx #注册中心名称,必填。
3.项目启动后注册中心可看到
1.新建一个SpringBoot项目
2.pom文件
4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.2 service-feign service-feign 1.0-SNAPSHOT service-feign 1.8 2020.0.5 org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-openfeign org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-maven-plugin
3.yml文件配置
server:
port: 8765
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: service-feign
4.启动类
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceFeignApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceFeignApplication.class, args);
}
}
5.启动后在注册中心可看到