├── microservice-discovery-eureka ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── spring │ │ │ └── cloud │ │ │ └── AppTest.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── spring │ │ └── cloud │ │ └── Application.java ├── pom.xml └── microservice-discovery-eureka.iml ├── microservice-config ├── config-client-prod.properties ├── config-client-test.properties ├── config-client-dev.properties ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── SpringcloudTest1ApplicationTests.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── cloud │ │ ├── ConfigApplication.java │ │ └── dto │ │ └── ResponseDto.java └── pom.xml ├── .gitignore ├── microservice-provide-user2 ├── target │ └── classes │ │ └── application.yml ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── user │ │ │ ├── UserApplication2.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ └── entity │ │ │ └── ResponseDto.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── user │ │ └── SpringcloudTest1ApplicationTests.java ├── pom.xml └── microservice-provide-user2.iml ├── microservice-config-client ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ ├── ConfigClinetApplication.java │ │ │ └── TestController.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── SpringcloudTest1ApplicationTests.java ├── pom.xml └── microservice-config-client.iml ├── microservice-config-client-cloud-bus ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ ├── CloudBusApplication.java │ │ │ └── TestController.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── SpringcloudTest1ApplicationTests.java └── pom.xml ├── microservice-sleuth-zipkin-server ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── zipkin │ │ │ └── ZipKinServerApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── zipkin │ │ └── SpringcloudTest1ApplicationTests.java └── pom.xml ├── microservice-feign-customize ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── feign │ │ │ ├── feign │ │ │ └── TestConfiguration.java │ │ │ ├── dao │ │ │ └── IFeignDao.java │ │ │ ├── FeignCustomizeApplication.java │ │ │ ├── controller │ │ │ └── ConsumptionContrroller.java │ │ │ └── dto │ │ │ └── ResponseDto.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── feign │ │ └── SpringcloudTest1ApplicationTests.java ├── pom.xml └── microservice-feign-customize.iml ├── microservice-hystrixdashboard-turbine ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── cloud │ │ │ │ ├── controller │ │ │ │ └── ConsumptionContrroller.java │ │ │ │ ├── dto │ │ │ │ └── ResponseDto.java │ │ │ │ └── HystrixTurbineApplication.java │ │ └── resources │ │ │ └── application.yml │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── SpringcloudTest1ApplicationTests.java └── pom.xml ├── microservice-ribbon ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── SpringcloudTest1ApplicationTests.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── cloud │ │ ├── dto │ │ └── ResponseDto.java │ │ ├── RibbonApplication.java │ │ └── controller │ │ └── ConsumptionContrroller.java ├── pom.xml └── microservice-ribbon.iml ├── microservice-feign ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── feign │ │ │ ├── config │ │ │ └── FeignFallBack.java │ │ │ ├── dao │ │ │ └── IFeignDao.java │ │ │ ├── controller │ │ │ └── ConsumptionContrroller.java │ │ │ ├── dto │ │ │ └── ResponseDto.java │ │ │ └── FeignApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── feign │ │ └── SpringcloudTest1ApplicationTests.java └── pom.xml ├── microservice-provide-user ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── user │ │ │ ├── UserApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ └── entity │ │ │ └── ResponseDto.java │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── user │ │ └── SpringcloudTest1ApplicationTests.java └── pom.xml ├── microservice-gateway-zuul ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── zuul │ │ │ └── SpringcloudTest1ApplicationTests.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── cloud │ │ └── zuul │ │ ├── ZuulApplication.java │ │ └── config │ │ ├── RequestLogFilter.java │ │ └── MyFallbackProvider.java └── pom.xml ├── microservice-ribbon-hystrixdashboard ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── SpringcloudTest1ApplicationTests.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── cloud │ │ ├── dto │ │ └── ResponseDto.java │ │ ├── RibbonHystrixApplication.java │ │ └── controller │ │ └── ConsumptionContrroller.java └── pom.xml ├── README.md ├── LICENSE └── pom.xml /microservice-discovery-eureka/src/test/java/com/spring/cloud/AppTest.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /microservice-config/config-client-prod.properties: -------------------------------------------------------------------------------- 1 | config.version = 0.3.1.prod -------------------------------------------------------------------------------- /microservice-config/config-client-test.properties: -------------------------------------------------------------------------------- 1 | config.version = 0.3.1.test -------------------------------------------------------------------------------- /microservice-config/config-client-dev.properties: -------------------------------------------------------------------------------- 1 | config.version = 0.4.3.dev 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /microservice-provide-user2/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 6 | instance: 7 | prefer-ip-address: true 8 | instance-id: ${spring.application.name}:${server.port} 9 | 10 | spring: 11 | application: 12 | name: micoserice-user 13 | server: 14 | port: 9997 -------------------------------------------------------------------------------- /microservice-config-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9004 3 | spring: 4 | application: 5 | name: microserice-config-client 6 | 7 | 8 | eureka: 9 | client: 10 | serviceUrl: 11 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 12 | instance: 13 | prefer-ip-address: true 14 | instance-id: ${spring.application.name}:${server.port} -------------------------------------------------------------------------------- /microservice-discovery-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | security: 2 | basic: 3 | enabled: true 4 | user: 5 | name: admin 6 | password: admin123 7 | server: 8 | port: 8761 9 | eureka: 10 | client: 11 | register-with-eureka: false #把eureka-client禁用掉 12 | fetch-registry: false 13 | service-url: 14 | defaultZone: http://admin:admin123@laclhost:8761/eureka -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9005 3 | spring: 4 | application: 5 | name: microserice-config-client 6 | 7 | eureka: 8 | client: 9 | serviceUrl: 10 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 11 | instance: 12 | prefer-ip-address: true 13 | instance-id: ${spring.application.name}:${server.port} -------------------------------------------------------------------------------- /microservice-sleuth-zipkin-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: micoserice-zipkin-server 4 | server: 5 | port: 9994 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 10 | instance: 11 | instance-id: ${spring.application.name}:${server.port} 12 | prefer-ip-address: true 13 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: micoserice-feign-customize 5 | server: 6 | port: 8055 7 | eureka: 8 | client: 9 | serviceUrl: 10 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 11 | instance: 12 | prefer-ip-address: true 13 | instance-id: ${spring.application.name}:${server.port} 14 | 15 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/src/main/java/com/cloud/controller/ConsumptionContrroller.java: -------------------------------------------------------------------------------- 1 | package com.cloud.controller; 2 | 3 | 4 | 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | /** 8 | * @author wxy 9 | */ 10 | @RestController 11 | @RequestMapping("/consumation") 12 | public class ConsumptionContrroller { 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /microservice-config-client/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: config-client 5 | # uri: http://localhost:9001/ #配置中心的具体位置 6 | profile: dev 7 | label: master 8 | discovery: 9 | #表示使用服务发现组件中的Config Server,不自己指定Config Server的uri,默认false 10 | enabled: true 11 | service-id: microservice-config 12 | management: 13 | security: 14 | enabled: false #取消权限拦截 默认开启 -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/src/main/java/com/cloud/CloudBusApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author wxy 8 | */ 9 | @SpringBootApplication 10 | public class CloudBusApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(CloudBusApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-config/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-ribbon/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: micoserice-feign 5 | zipkin: 6 | base-url: http://localhost:9994 7 | server: 8 | port: 8050 9 | eureka: 10 | client: 11 | serviceUrl: 12 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 13 | instance: 14 | instance-id: ${spring.application.name}:${server.port} 15 | prefer-ip-address: true 16 | feign: 17 | hystrix: 18 | enabled: true 19 | -------------------------------------------------------------------------------- /microservice-config-client/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-feign/src/test/java/com/cloud/feign/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-provide-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 6 | instance: 7 | prefer-ip-address: true 8 | instance-id: ${spring.application.name}:${server.port} 9 | 10 | spring: 11 | application: 12 | name: micoserice-user 13 | zipkin: 14 | base-url: http://localhost:9994 15 | sleuth: 16 | sampler: 17 | percentage: 1.0 18 | server: 19 | port: 9998 -------------------------------------------------------------------------------- /microservice-provide-user2/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 6 | instance: 7 | prefer-ip-address: true 8 | instance-id: ${spring.application.name}:${server.port} 9 | 10 | spring: 11 | application: 12 | name: micoserice-user 13 | zipkin: 14 | base-url: http://localhost:9994 15 | sleuth: 16 | sampler: 17 | percentage: 1.0 18 | server: 19 | port: 9997 -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/test/java/com/cloud/zuul/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zuul; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-provide-user/src/test/java/com/cloud/user/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-provide-user2/src/test/java/com/cloud/user/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/src/test/java/com/cloud/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/test/java/com/cloud/feign/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-sleuth-zipkin-server/src/test/java/com/cloud/zipkin/SpringcloudTest1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zipkin; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringcloudTest1ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringCloud 2 | SpringCloud-示例项目简单说明 3 | 4 | `microservice-discovery-eureka`:服务发现,eureka服务注册中心,以及使用spring-security验证登陆 5 | 6 | `micoservice-provide-user, 7 | micoservice-provide-user2`:服务提供者,两个消费者便于负载均衡实验 8 | 9 | `microservice-ribbon`:客户端负载均衡ribbon使用示例,以及ribbon中hystrix熔断器的简单使用示例 10 | 11 | `microservice-feign`:声明式REST客户端Feign使用示例,和reign中自带的hystrix的简单使用 12 | 13 | `microservice-ribbon-hystrixdashboard`:ribbon中配置hystrix-dashboard,feign的配置与ribbon无异 14 | 15 | `micoserice-gateway-zuul`:api-gateway zuul使用示例,路由配置,header配置等 -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/java/com/cloud/feign/feign/TestConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.feign; 2 | 3 | import feign.Contract; 4 | import org.springframework.cloud.netflix.ribbon.RibbonClient; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class TestConfiguration { 10 | 11 | @Bean 12 | public Contract feignContract() { 13 | return new feign.Contract.Default(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8020 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 7 | instance: 8 | prefer-ip-address: true 9 | instance-id: ${spring.application.name}:${server.port} 10 | spring: 11 | application: 12 | name: microservice-ribbon-hystrixdashboard 13 | #management: 14 | # port: 54001 15 | # health: 16 | # mail: 17 | # enabled: false 18 | # dashboard 访问 http://localhost:8020/hystrix 19 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/src/main/java/com/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.spring.cloud; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | /** 9 | * eureka application 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaServer 13 | public class Application{ 14 | public static void main( String[] args ) { 15 | SpringApplication.run(Application.class,args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /microservice-config-client/src/main/java/com/cloud/ConfigClinetApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.beans.factory.annotation.Configurable; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class ConfigClinetApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigClinetApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/java/com/cloud/feign/dao/IFeignDao.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.dao; 2 | 3 | import com.cloud.feign.dto.ResponseDto; 4 | import com.cloud.feign.feign.TestConfiguration; 5 | import feign.RequestLine; 6 | import org.springframework.cloud.netflix.feign.FeignClient; 7 | 8 | @FeignClient(name = "micoserice-zipkin",configuration = TestConfiguration.class) 9 | public interface IFeignDao { 10 | //@RequestMapping(value = "/zipkin/getuser",method = RequestMethod.GET) 11 | @RequestLine("GET /zipkin/getuser") 12 | ResponseDto getUser(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /microservice-provide-user/src/main/java/com/cloud/user/UserApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | public class UserApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(UserApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-ribbon/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 7 | instance: 8 | prefer-ip-address: true 9 | instance-id: ${spring.application.name}:${server.port} 10 | spring: 11 | application: 12 | name: micoserice-ribbon 13 | 14 | #management: 15 | # port: 54001 16 | # health: 17 | # mail: 18 | # enabled: false 19 | 20 | zipkin: 21 | base-url: http://localhost:9994 22 | sleuth: 23 | sampler: 24 | percentage: 1.0 25 | -------------------------------------------------------------------------------- /microservice-provide-user2/src/main/java/com/cloud/user/UserApplication2.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | public class UserApplication2 { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(UserApplication2.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-feign/src/main/java/com/cloud/feign/config/FeignFallBack.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.config; 2 | 3 | import com.cloud.feign.dao.IFeignDao; 4 | import com.cloud.feign.dto.ResponseDto; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author wxy 10 | */ 11 | @Component 12 | public class FeignFallBack implements IFeignDao { 13 | @Override 14 | public ResponseDto getUser() { 15 | ResponseDto dto = new ResponseDto(); 16 | dto.setCode(1); 17 | return dto; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: #添加rabbitmq配置 3 | host: 192.168.146.128 4 | port: 5672 #management 15672 5 | username: admin 6 | password: admin 7 | cloud: 8 | config: 9 | name: config-client 10 | #uri: http://localhost:9001/ #配置中心的具体位置 11 | profile: dev 12 | label: master 13 | discovery: 14 | #表示使用服务发现组件中的Config Server,不自己指定Config Server的uri,默认false 15 | enabled: true 16 | service-id: microservice-config 17 | management: 18 | security: 19 | enabled: false #取消权限拦截 默认开启 20 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/java/com/cloud/feign/FeignCustomizeApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableFeignClients 11 | public class FeignCustomizeApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(FeignCustomizeApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /microservice-sleuth-zipkin-server/src/main/java/com/cloud/zipkin/ZipKinServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import zipkin.server.EnableZipkinServer; 7 | 8 | /** 9 | * @author wxy 10 | */ 11 | @SpringBootApplication 12 | @EnableZipkinServer 13 | @EnableEurekaClient 14 | public class ZipKinServerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ZipKinServerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /microservice-config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 5 | instance: 6 | prefer-ip-address: true 7 | instance-id: ${spring.application.name}:${server.port} 8 | 9 | server: 10 | port: 9001 11 | spring: 12 | application: 13 | name: microservice-config 14 | cloud: 15 | config: 16 | server: 17 | git: 18 | uri: https://github.com/xiaoyangw/springcloud/ #git仓库地址 19 | search-paths: microservice-config #配置仓库路径(目标文件路径) 20 | username: 1483863489@qq.com #git账户名 21 | password: xiao02yang24 #git账户密码 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 7 | instance: 8 | prefer-ip-address: true 9 | instance-id: ${spring.application.name}:${server.port} 10 | spring: 11 | application: 12 | name: hystrix-turbine-dashboard 13 | 14 | turbine: 15 | app-config: microservice-ribbon-hystrixdashboard,micoserice-ribbon 16 | aggregator: 17 | cluster-config: default 18 | cluster-name-expression: new String("default") 19 | 20 | #management: 21 | # port: 54001 22 | # health: 23 | # mail: 24 | # enabled: false 25 | -------------------------------------------------------------------------------- /microservice-provide-user/src/main/java/com/cloud/user/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user.controller; 2 | 3 | import com.cloud.user.entity.ResponseDto; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RequestMapping("/user") 10 | public class UserController { 11 | 12 | @GetMapping("/getuser") 13 | public ResponseDto getUser(){ 14 | ResponseDto dto = new ResponseDto(); 15 | dto.setCode(0); 16 | dto.setMsg("user--------------111"); 17 | return dto; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /microservice-provide-user2/src/main/java/com/cloud/user/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user.controller; 2 | 3 | import com.cloud.user.entity.ResponseDto; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RequestMapping("/user") 10 | public class UserController { 11 | 12 | @GetMapping("/getuser") 13 | public ResponseDto getUser(){ 14 | ResponseDto dto = new ResponseDto(); 15 | dto.setCode(0); 16 | dto.setMsg("user-------------222"); 17 | return dto; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /microservice-config/src/main/java/com/cloud/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.beans.factory.annotation.Configurable; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.config.server.EnableConfigServer; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | 10 | @Configurable 11 | @EnableAutoConfiguration 12 | @EnableEurekaClient 13 | @EnableConfigServer 14 | public class ConfigApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ConfigApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/src/main/java/com/cloud/TestController.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author wxy 11 | * bus刷新节点 curl -X POST http://host/bus/refresh 12 | */ 13 | @RestController 14 | public class TestController { 15 | @Value("${config.version}") 16 | private String version; 17 | 18 | @GetMapping("/version") 19 | public String test(){ 20 | return version; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /microservice-feign/src/main/java/com/cloud/feign/dao/IFeignDao.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.dao; 2 | 3 | import com.cloud.feign.config.FeignFallBack; 4 | import com.cloud.feign.dto.ResponseDto; 5 | import org.springframework.cloud.netflix.feign.FeignClient; 6 | import org.springframework.stereotype.Repository; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | 12 | @Repository 13 | @FeignClient(value = "micoserice-user",fallback = FeignFallBack.class) 14 | public interface IFeignDao { 15 | 16 | @RequestMapping(value = "/user/getuser",method = RequestMethod.GET) 17 | ResponseDto getUser(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /microservice-config-client/src/main/java/com/cloud/TestController.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author wxy 11 | *使用@RefreshScope开启手动刷新配置开启refresh节点 使用命令 curl -X POST http://hostname/refresh 12 | */ 13 | @RestController 14 | @RefreshScope 15 | public class TestController { 16 | @Value("${config.version}") 17 | private String version; 18 | 19 | @GetMapping("/version") 20 | public String test(){ 21 | return version; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/java/com/cloud/feign/controller/ConsumptionContrroller.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.controller; 2 | 3 | 4 | import com.cloud.feign.dao.IFeignDao; 5 | import com.cloud.feign.dto.ResponseDto; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * @author wxy 14 | */ 15 | @RestController 16 | @RequestMapping("/consumation") 17 | public class ConsumptionContrroller { 18 | 19 | @Autowired 20 | private IFeignDao iFeignDao; 21 | 22 | @GetMapping("/getuser") 23 | public ResponseDto getUser(){ 24 | return iFeignDao.getUser(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /microservice-feign/src/main/java/com/cloud/feign/controller/ConsumptionContrroller.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.controller; 2 | 3 | 4 | import com.cloud.feign.dao.IFeignDao; 5 | import com.cloud.feign.dto.ResponseDto; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * @author wxy 14 | */ 15 | @RestController 16 | @RequestMapping("/consumation") 17 | public class ConsumptionContrroller { 18 | 19 | private IFeignDao iFeignDao; 20 | 21 | @Autowired 22 | public ConsumptionContrroller(IFeignDao iFeignDao) { 23 | this.iFeignDao=iFeignDao; 24 | } 25 | 26 | @GetMapping("/getuser") 27 | public ResponseDto getUser(){ 28 | return iFeignDao.getUser(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /microservice-config/src/main/java/com/cloud/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-ribbon/src/main/java/com/cloud/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-feign/src/main/java/com/cloud/feign/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-feign-customize/src/main/java/com/cloud/feign/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/src/main/java/com/cloud/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/src/main/java/com/cloud/dto/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.dto; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-provide-user/src/main/java/com/cloud/user/entity/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user.entity; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-provide-user2/src/main/java/com/cloud/user/entity/ResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.cloud.user.entity; 2 | 3 | /** 4 | * 接口返回结果封装 5 | * 6 | */ 7 | public class ResponseDto { 8 | 9 | public Integer code; 10 | public Object data; 11 | public String msg; 12 | 13 | public Integer getCode() { 14 | return code; 15 | } 16 | 17 | public void setCode(Integer code) { 18 | this.code = code; 19 | } 20 | 21 | public Object getData() { 22 | return data; 23 | } 24 | 25 | public void setData(Object data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Resphonse{" + 40 | "code=" + code + 41 | ", data=" + data + 42 | ", msg='" + msg + '\'' + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /microservice-ribbon/src/main/java/com/cloud/RibbonApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | @SpringBootApplication 13 | @EnableEurekaClient 14 | @EnableCircuitBreaker 15 | @EnableHystrixDashboard 16 | public class RibbonApplication { 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate(){ 21 | return new RestTemplate(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(RibbonApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/src/main/java/com/cloud/HystrixTurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | @SpringBootApplication 13 | @EnableEurekaClient 14 | @EnableHystrixDashboard 15 | @EnableTurbine 16 | public class HystrixTurbineApplication { 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate(){ 21 | return new RestTemplate(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(HystrixTurbineApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/src/main/java/com/cloud/RibbonHystrixApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | @SpringBootApplication 13 | @EnableEurekaClient 14 | @EnableCircuitBreaker 15 | @EnableHystrixDashboard 16 | public class RibbonHystrixApplication { 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate(){ 21 | return new RestTemplate(); 22 | } 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(RibbonHystrixApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /microservice-feign/src/main/java/com/cloud/feign/FeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.feign; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.ComponentScan; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.web.client.RestTemplate; 14 | 15 | @SpringBootApplication 16 | @EnableEurekaClient 17 | @EnableFeignClients 18 | //@EnableCircuitBreaker 19 | public class FeignApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(FeignApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 晓阳 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #zuul注册到Eureka-service为服务后默认情况下是构建PAI-GATEWAY,只要在url这样拼接 zuul-host/appname/api 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://admin:admin123@localhost:8761/eureka/ 6 | instance: 7 | prefer-ip-address: true 8 | instance-id: ${spring.application.name}:${server.port} 9 | 10 | spring: 11 | application: 12 | name: micoserice-gateway-zuul 13 | zipkin: 14 | base-url: http://192.168.146.131:9994 15 | sleuth: 16 | sampler: 17 | percentage: 1.0 18 | server: 19 | port: 8090 20 | 21 | # zuul 路由配置 方式一 22 | #zuul: 23 | # routes: 24 | # micoserice-zipkin: /zipkin/** 25 | #忽略微服务,多个微服务用逗号隔开,忽略所有的服务时用'*'表示 26 | # ignored-services: micoserice-feign,micoserice-ribbon 27 | 28 | #方式二,效果和方式一一样 29 | #zuul: 30 | # routes: 31 | # zipkin-routes: #zipkin-routes只是一个路由名称可任意起名 32 | # service-id: micoserice-zipkin 33 | # path: /zipkin/** #service-id 对应路径 34 | # ignored-services: /**/admin/** #忽略所有包含/admin/的路径 35 | # sensitive-headers: Cookie,Set-Cookie,Authorization #设置敏感header信息 36 | # ignored-headers: header1,header2 #设置忽略header,设置后header1,header2将不会传到其他的微服务。 37 | 38 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/java/com/cloud/zuul/ZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zuul; 2 | 3 | import com.cloud.zuul.config.RequestLogFilter; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | @SpringBootApplication 11 | @EnableZuulProxy 12 | public class ZuulApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ZuulApplication.class, args); 16 | } 17 | 18 | /** 19 | * 使用正则表达式方式路由, 20 | * 添加该方式后,在原有的服务中,appname-v1, 21 | * 如 micoserice-zipkin-v1 22 | * @return 23 | */ 24 | /*@Bean 25 | public PatternServiceRouteMapper serviceRouteMapper(){ 26 | return new PatternServiceRouteMapper( 27 | "(?^.+)-(?v.+$)", 28 | "${version}/${name}"); 29 | }*/ 30 | 31 | /** 32 | * 添加zuul过滤器Bean 33 | * @return RequestLogFilter 34 | */ 35 | @Bean 36 | public RequestLogFilter getRequestLogFilter(){ 37 | return new RequestLogFilter(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /microservice-ribbon/src/main/java/com/cloud/controller/ConsumptionContrroller.java: -------------------------------------------------------------------------------- 1 | package com.cloud.controller; 2 | 3 | 4 | import com.cloud.dto.ResponseDto; 5 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * @author wxy 14 | */ 15 | @RestController 16 | @RequestMapping("/consumation") 17 | public class ConsumptionContrroller { 18 | private RestTemplate restTemplate; 19 | @Autowired 20 | public ConsumptionContrroller(RestTemplate restTemplate) { 21 | this.restTemplate = restTemplate; 22 | } 23 | 24 | @HystrixCommand(fallbackMethod = "error") 25 | @GetMapping("/getuser2") 26 | public ResponseDto getUser(){ 27 | return restTemplate.getForObject("http://MICOSERICE-USER/user/getuser",ResponseDto.class); 28 | } 29 | 30 | public ResponseDto error(){ 31 | ResponseDto dto = new ResponseDto(); 32 | dto.setCode(1); 33 | dto.setMsg("error"); 34 | return dto; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/src/main/java/com/cloud/controller/ConsumptionContrroller.java: -------------------------------------------------------------------------------- 1 | package com.cloud.controller; 2 | 3 | 4 | import com.cloud.dto.ResponseDto; 5 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * @author wxy 14 | */ 15 | @RestController 16 | @RequestMapping("/consumation") 17 | public class ConsumptionContrroller { 18 | private RestTemplate restTemplate; 19 | @Autowired 20 | public ConsumptionContrroller(RestTemplate restTemplate) { 21 | this.restTemplate = restTemplate; 22 | } 23 | 24 | @HystrixCommand(fallbackMethod = "error") 25 | @GetMapping("/getuser") 26 | public ResponseDto getUser(){ 27 | return restTemplate.getForObject("http://MICOSERICE-USER/zipkin/getuser",ResponseDto.class); 28 | } 29 | 30 | public ResponseDto error(){ 31 | ResponseDto dto = new ResponseDto(); 32 | dto.setCode(1); 33 | dto.setMsg("error"); 34 | return dto; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.spring.cloud 7 | spring-cloud-microservice 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | microservice-discovery-eureka 12 | jar 13 | 14 | 15 | UTF-8 16 | 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-eureka-server 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-security 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-gateway-zuul 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-test 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-zuul 34 | 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-zipkin 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /microservice-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-config 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-netflix-eureka-client 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-config-server 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /microservice-feign-customize/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-feign-customize 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-openfeign 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-actuator 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /microservice-config-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-config-client 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-netflix-eureka-client 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-config 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /microservice-provide-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-provide-user 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-zipkin 42 | 43 | 44 | junit 45 | junit 46 | test 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /microservice-provide-user2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-provide-user2 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-zipkin 42 | 43 | 44 | junit 45 | junit 46 | test 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/java/com/cloud/zuul/config/RequestLogFilter.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zuul.config; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import javax.servlet.http.HttpServletRequest; 8 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE; 9 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.SIMPLE_HOST_ROUTING_FILTER_ORDER; 10 | 11 | /** 12 | * @author wxy 13 | * zuul过滤器 14 | * zuul中定义了四种标准过滤类型,这些过滤类型对应请求的生命周期 15 | * 16 | * PRE:这种过滤类型在请求被路由之前调用。可利用这种过滤器实现身份验证,在集群中选择请求的微服务,记录调试信息等。 17 | * 18 | * ROUTING:这种过滤器将请求路由到微服务。这种过滤用于构建发送给微服务的请求, 19 | * 并可以使用Apache HttpClient,Fegin,Ribbon请求微服务。 20 | * POST:这种过滤器在路由到微服务以后执行。这种过滤器可用来微响应添加标准的http header, 21 | * 搜集统计信息和指标,将响应发送给客户端。 22 | * ERROR:在其他阶段发生错误时执行该过滤器。 23 | * 24 | * http://cloud.spring.io/spring-cloud-static/Finchley.M2/#_router_and_filter_zuul 25 | */ 26 | public class RequestLogFilter extends ZuulFilter { 27 | private static Logger logger = LoggerFactory.getLogger(RequestLogFilter.class); 28 | @Override 29 | public String filterType() { 30 | return PRE_TYPE; 31 | } 32 | 33 | @Override 34 | public int filterOrder() { 35 | return 1; 36 | } 37 | 38 | @Override 39 | public boolean shouldFilter() { 40 | return true; 41 | } 42 | 43 | @Override 44 | public Object run() { 45 | RequestContext requestContext =RequestContext.getCurrentContext(); 46 | HttpServletRequest request = requestContext.getRequest(); 47 | logger.info(String.format("send %s request to %s",request.getMethod(),request.getRequestURL().toString())); 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /microservice-feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-feign 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-openfeign 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | 43 | 44 | 45 | org.springframework.cloud 46 | spring-cloud-starter-zipkin 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /microservice-ribbon-hystrixdashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-ribbon-hystrixdashboard 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-hystrix-dashboard 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-netflix-hystrix 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /microservice-config-client-cloud-bus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-config-client-cloud-bus 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-netflix-eureka-client 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-config 38 | 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-starter-bus-amqp 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /microservice-sleuth-zipkin-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-sleuth-zipkin-server 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka 25 | 26 | 27 | io.zipkin.java 28 | zipkin-autoconfigure-ui 29 | 30 | 31 | io.zipkin.java 32 | zipkin-server 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-actuator 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | 47 | 48 | 49 | junit 50 | junit 51 | test 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /microservice-hystrixdashboard-turbine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-hystrixdashboard-turbine 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-actuator 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-starter-hystrix-dashboard 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-starter-turbine 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-netflix-turbine 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /microservice-ribbon/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-ribbon 7 | jar 8 | 9 | 10 | com.spring.cloud 11 | spring-cloud-microservice 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-eureka 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-hystrix-dashboard 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-netflix-hystrix 42 | 43 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | 51 | 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-zipkin 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /microservice-gateway-zuul/src/main/java/com/cloud/zuul/config/MyFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.cloud.zuul.config; 2 | 3 | import org.springframework.beans.factory.annotation.Configurable; 4 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 5 | import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.http.client.ClientHttpResponse; 10 | import org.springframework.stereotype.Component; 11 | 12 | import java.io.ByteArrayInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.nio.charset.Charset; 16 | 17 | /** 18 | * @author wxy 19 | * zuul中使用hystrix的回退 20 | */ 21 | @Component 22 | public class MyFallbackProvider implements FallbackProvider { 23 | @Override 24 | public String getRoute() { 25 | //路由配置micoserice-zipkin,如果全部用"*"代替 26 | return "micoserice-zipkin"; 27 | } 28 | 29 | @Override 30 | public ClientHttpResponse fallbackResponse() { 31 | return new ClientHttpResponse() { 32 | @Override 33 | public HttpStatus getStatusCode() throws IOException { 34 | //回退的状态码 35 | return HttpStatus.OK; 36 | } 37 | 38 | @Override 39 | public int getRawStatusCode() throws IOException { 40 | //数字类型状态码 41 | return 200; 42 | } 43 | 44 | @Override 45 | public String getStatusText() throws IOException { 46 | //状态文本 47 | return "ok"; 48 | } 49 | 50 | @Override 51 | public void close() { 52 | 53 | } 54 | 55 | @Override 56 | public InputStream getBody() throws IOException { 57 | //回退响应体 58 | return new ByteArrayInputStream("服务不可用稍后再试".getBytes()); 59 | } 60 | 61 | @Override 62 | public HttpHeaders getHeaders() { 63 | //header设置 64 | HttpHeaders headers = new HttpHeaders(); 65 | MediaType mediaType = new MediaType("application","json", Charset.forName("UTF-8")); 66 | headers.setContentType(mediaType); 67 | return headers; 68 | } 69 | }; 70 | } 71 | 72 | @Override 73 | public ClientHttpResponse fallbackResponse(Throwable cause) { 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.spring.cloud 7 | spring-cloud-microservice 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | 12 | microservice-provide-user 13 | microservice-provide-user2 14 | microservice-discovery-eureka 15 | microservice-ribbon 16 | microservice-feign 17 | microservice-feign-customize 18 | microservice-ribbon-hystrixdashboard 19 | microservice-hystrixdashboard-turbine 20 | microservice-gateway-zuul 21 | microservice-config 22 | microservice-config-client 23 | microservice-config-client-cloud-bus 24 | microservice-sleuth-zipkin-server 25 | spring-cloud-gateway 26 | 27 | 28 | 29 | UTF-8 30 | UTF-8 31 | 1.8 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-parent 37 | 1.5.9.RELEASE 38 | 39 | 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-dependencies 44 | Edgware.RELEASE 45 | pom 46 | import 47 | 48 | 49 | 50 | 51 | 52 | spring-milestones 53 | Spring Milestones 54 | https://repo.spring.io/libs-milestone 55 | 56 | false 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /microservice-discovery-eureka/microservice-discovery-eureka.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /microservice-provide-user2/microservice-provide-user2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /microservice-config-client/microservice-config-client.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /microservice-feign-customize/microservice-feign-customize.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /microservice-ribbon/microservice-ribbon.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | --------------------------------------------------------------------------------