diff --git a/README.md b/README.md index 456849d..c30d720 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Spring cloud使用的各种示例,以最简单、最实用为标准 - [spring-cloud-eureka](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-eureka):eureka server单机、双机、集群示例 - [service-producer-consumer](https://github.com/ityouknow/spring-cloud-starter/tree/master/service-producer-consumer):利用eureka实现服务提供与调用demo -- [spring-cloud-hystrix](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-hystrix):Hystrix熔断的使用 +- [spring-cloud-hystrix](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-hystrix):Hystrix熔断的使用示例 +- [hystrix-dashboard-turbine](https://github.com/ityouknow/spring-cloud-starter/tree/master/hystrix-dashboard-turbine):熔断监控Hystrix Dashboard和Turbine的示例 @@ -17,7 +18,7 @@ Spring cloud使用的各种示例,以最简单、最实用为标准 - [springcloud(二):注册中心Eureka](http://www.ityouknow.com/springcloud/2017/05/10/springcloud-eureka.html) - [springcloud(三):服务提供与调用](http://www.ityouknow.com/springcloud/2017/05/12/service-provider-constomer.html) - [springcloud(四):熔断器Hystrix](http://www.ityouknow.com/springcloud/2017/05/16/springcloud-hystrix.html) - +- [springcloud(五):熔断监控Hystrix Dashboard和Turbine](http://www.ityouknow.com/springcloud/2017/05/18/hystrix-dashboard-turbine.html) > 如果大家想了解关于springcloud的其它方面应用,也可以以issues的形式反馈给我,我后续来完善。 diff --git a/hystrix-dashboard-turbine/hystrix-dashboard-turbine/pom.xml b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/pom.xml new file mode 100644 index 0000000..7f51d0a --- /dev/null +++ b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + com.neo + hystrix-dashboard-turbine + 0.0.1-SNAPSHOT + jar + + hystrix-dashboard-turbine + Demo project for Spring cloud hystrix dashboard and turbine + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-turbine + + + org.springframework.cloud + spring-cloud-netflix-turbine + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-hystrix-dashboard + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/java/com/neo/DashboardApplication.java b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/java/com/neo/DashboardApplication.java new file mode 100644 index 0000000..69c8d6c --- /dev/null +++ b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/java/com/neo/DashboardApplication.java @@ -0,0 +1,17 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; +import org.springframework.cloud.netflix.turbine.EnableTurbine; + +@SpringBootApplication +@EnableHystrixDashboard +@EnableTurbine +public class DashboardApplication { + + public static void main(String[] args) { + SpringApplication.run(DashboardApplication.class, args); + } + +} diff --git a/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/resources/application.properties b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/resources/application.properties new file mode 100644 index 0000000..1a6d6de --- /dev/null +++ b/hystrix-dashboard-turbine/hystrix-dashboard-turbine/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.application.name=hystrix-dashboard-turbine +server.port=8001 +turbine.appConfig=node01,node02 +turbine.aggregator.clusterConfig= default +turbine.clusterNameExpression= new String("default") + +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ \ No newline at end of file diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/pom.xml b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/pom.xml new file mode 100644 index 0000000..9ad4148 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.neo + spring-cloud-consumer-hystrix-dashboard + 0.0.1-SNAPSHOT + jar + + spring-cloud-consumer-hystrix-dashboard + Demo project for Spring cloud consumer hystrix dashboard + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.cloud + spring-cloud-starter-hystrix-dashboard + + + org.springframework.boot + spring-boot-starter-actuator + + + 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 + + + + + + diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/ConsumerApplication.java b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/ConsumerApplication.java new file mode 100644 index 0000000..21cc282 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/ConsumerApplication.java @@ -0,0 +1,21 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@EnableHystrixDashboard +@EnableCircuitBreaker +public class ConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } +} diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/controller/ConsumerController.java b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/controller/ConsumerController.java similarity index 100% rename from spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/controller/ConsumerController.java rename to hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/controller/ConsumerController.java diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/remote/HelloRemote.java b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/remote/HelloRemote.java similarity index 100% rename from spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/remote/HelloRemote.java rename to hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/remote/HelloRemote.java diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/remote/HelloRemoteHystrix.java b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/remote/HelloRemoteHystrix.java similarity index 100% rename from spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/remote/HelloRemoteHystrix.java rename to hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/java/com/neo/remote/HelloRemoteHystrix.java diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/resources/application.properties b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/resources/application.properties new file mode 100644 index 0000000..2d0b5a7 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.application.name=spring-cloud-consumer-hystrix-dashboard +server.port=9001 +feign.hystrix.enabled=true +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/test/java/com/neo/ProducerApplicationTests.java b/hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/test/java/com/neo/ProducerApplicationTests.java similarity index 100% rename from spring-cloud-hystrix/spring-cloud-consumer/src/test/java/com/neo/ProducerApplicationTests.java rename to hystrix-dashboard-turbine/spring-cloud-consumer-hystrix-dashboard/src/test/java/com/neo/ProducerApplicationTests.java diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/pom.xml b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/pom.xml new file mode 100644 index 0000000..928d1ee --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + com.neo + spring-cloud-consumer-node1 + 0.0.1-SNAPSHOT + jar + + spring-cloud-consumer-node1 + Demo project for Spring cloud consumer + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-starter-actuator + + + 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 + + + + + + diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/ConsumerApplication.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/ConsumerApplication.java new file mode 100644 index 0000000..82ffb2a --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/ConsumerApplication.java @@ -0,0 +1,18 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@EnableCircuitBreaker +public class ConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/controller/ConsumerController.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/controller/ConsumerController.java new file mode 100644 index 0000000..6b4b2dc --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/controller/ConsumerController.java @@ -0,0 +1,20 @@ +package com.neo.controller; + +import com.neo.remote.HelloRemote; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ConsumerController { + + @Autowired + HelloRemote HelloRemote; + + @RequestMapping("/hello/{name}") + public String index(@PathVariable("name") String name) { + return HelloRemote.hello(name); + } + +} \ No newline at end of file diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemote.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemote.java new file mode 100644 index 0000000..3d64410 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemote.java @@ -0,0 +1,16 @@ +package com.neo.remote; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/11. + */ +@FeignClient(name= "spring-cloud-producer", fallback = HelloRemoteHystrix.class) +public interface HelloRemote { + + @RequestMapping(value = "/hello") + public String hello(@RequestParam(value = "name") String name); + +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemoteHystrix.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemoteHystrix.java new file mode 100644 index 0000000..973a4f3 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/java/com/neo/remote/HelloRemoteHystrix.java @@ -0,0 +1,17 @@ +package com.neo.remote; + +import com.neo.remote.HelloRemote; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/15. + */ +@Component +public class HelloRemoteHystrix implements HelloRemote{ + + @Override + public String hello(@RequestParam(value = "name") String name) { + return "hello " +name+", this messge send failed "; + } +} diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/main/resources/application.properties b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/resources/application.properties similarity index 70% rename from spring-cloud-hystrix/spring-cloud-consumer/src/main/resources/application.properties rename to hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/resources/application.properties index 921b77b..7f99dc7 100644 --- a/spring-cloud-hystrix/spring-cloud-consumer/src/main/resources/application.properties +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/main/resources/application.properties @@ -1,5 +1,6 @@ -spring.application.name=spring-cloud-consumer +spring.application.name=node01 server.port=9001 feign.hystrix.enabled=true + eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/test/java/com/neo/ProducerApplicationTests.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/test/java/com/neo/ProducerApplicationTests.java new file mode 100644 index 0000000..677161e --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node1/src/test/java/com/neo/ProducerApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/pom.xml b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/pom.xml new file mode 100644 index 0000000..957fea6 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + com.neo + spring-cloud-consumer-node2 + 0.0.1-SNAPSHOT + jar + + spring-cloud-consumer-node2 + Demo project for Spring cloud consumer + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-starter-actuator + + + 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 + + + + + + diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/ConsumerApplication.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/ConsumerApplication.java new file mode 100644 index 0000000..82ffb2a --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/ConsumerApplication.java @@ -0,0 +1,18 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@EnableCircuitBreaker +public class ConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/controller/ConsumerController.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/controller/ConsumerController.java new file mode 100644 index 0000000..0a0deb4 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/controller/ConsumerController.java @@ -0,0 +1,20 @@ +package com.neo.controller; + +import com.neo.remote.HelloRemote; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ConsumerController { + + @Autowired + HelloRemote HelloRemote; + + @RequestMapping("/hello/{name}") + public String index(@PathVariable("name") String name) { + return HelloRemote.hello2(name); + } + +} \ No newline at end of file diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemote.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemote.java new file mode 100644 index 0000000..f4b5380 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemote.java @@ -0,0 +1,16 @@ +package com.neo.remote; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/11. + */ +@FeignClient(name= "spring-cloud-producer2", fallback = HelloRemoteHystrix.class) +public interface HelloRemote { + + @RequestMapping(value = "/hello") + public String hello2(@RequestParam(value = "name") String name); + +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemoteHystrix.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemoteHystrix.java new file mode 100644 index 0000000..15ed424 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/java/com/neo/remote/HelloRemoteHystrix.java @@ -0,0 +1,17 @@ +package com.neo.remote; + +import com.neo.remote.HelloRemote; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/15. + */ +@Component +public class HelloRemoteHystrix implements HelloRemote{ + + @Override + public String hello2(@RequestParam(value = "name") String name) { + return "hello " +name+", this messge send failed "; + } +} diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/resources/application.properties b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/resources/application.properties new file mode 100644 index 0000000..81ed778 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=node02 +server.port=9002 +feign.hystrix.enabled=true + +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/test/java/com/neo/ProducerApplicationTests.java b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/test/java/com/neo/ProducerApplicationTests.java new file mode 100644 index 0000000..677161e --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-consumer-node2/src/test/java/com/neo/ProducerApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/hystrix-dashboard-turbine/spring-cloud-eureka/pom.xml b/hystrix-dashboard-turbine/spring-cloud-eureka/pom.xml new file mode 100644 index 0000000..23d7a60 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-eureka/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.neo + spring-cloud-eureka + 0.0.1-SNAPSHOT + jar + + spring-cloud-eureka + Demo project for Spring cloud eureka + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter + + + org.springframework.cloud + spring-cloud-starter-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 + + + + + + diff --git a/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java b/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java new file mode 100644 index 0000000..5d47795 --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class SpringCloudEurekaApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringCloudEurekaApplication.class, args); + } +} diff --git a/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/resources/application.properties b/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/resources/application.properties new file mode 100644 index 0000000..124b09d --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-eureka/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=spring-cloud-eureka + +server.port=8000 +eureka.client.register-with-eureka=false +eureka.client.fetch-registry=false + +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/hystrix-dashboard-turbine/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java b/hystrix-dashboard-turbine/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java new file mode 100644 index 0000000..d536a6b --- /dev/null +++ b/hystrix-dashboard-turbine/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringCloudEurekaApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-cloud-hystrix/spring-cloud-consumer/pom.xml b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/pom.xml similarity index 91% rename from spring-cloud-hystrix/spring-cloud-consumer/pom.xml rename to spring-cloud-hystrix/spring-cloud-consumer-hystrix/pom.xml index 4752a64..2dad4a4 100644 --- a/spring-cloud-hystrix/spring-cloud-consumer/pom.xml +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/pom.xml @@ -4,12 +4,12 @@ 4.0.0 com.neo - spring-cloud-consumer + spring-cloud-consumer-hystrix 0.0.1-SNAPSHOT jar - spring-cloud-consumer - Demo project for Spring cloud consumer + spring-cloud-consumer-hystrix + Demo project for Spring cloud consumer hystrix org.springframework.boot diff --git a/spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/ConsumerApplication.java b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/ConsumerApplication.java similarity index 100% rename from spring-cloud-hystrix/spring-cloud-consumer/src/main/java/com/neo/ConsumerApplication.java rename to spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/ConsumerApplication.java diff --git a/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/controller/ConsumerController.java b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/controller/ConsumerController.java new file mode 100644 index 0000000..6b4b2dc --- /dev/null +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/controller/ConsumerController.java @@ -0,0 +1,20 @@ +package com.neo.controller; + +import com.neo.remote.HelloRemote; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ConsumerController { + + @Autowired + HelloRemote HelloRemote; + + @RequestMapping("/hello/{name}") + public String index(@PathVariable("name") String name) { + return HelloRemote.hello(name); + } + +} \ No newline at end of file diff --git a/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemote.java b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemote.java new file mode 100644 index 0000000..3d64410 --- /dev/null +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemote.java @@ -0,0 +1,16 @@ +package com.neo.remote; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/11. + */ +@FeignClient(name= "spring-cloud-producer", fallback = HelloRemoteHystrix.class) +public interface HelloRemote { + + @RequestMapping(value = "/hello") + public String hello(@RequestParam(value = "name") String name); + +} diff --git a/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemoteHystrix.java b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemoteHystrix.java new file mode 100644 index 0000000..973a4f3 --- /dev/null +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/java/com/neo/remote/HelloRemoteHystrix.java @@ -0,0 +1,17 @@ +package com.neo.remote; + +import com.neo.remote.HelloRemote; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by summer on 2017/5/15. + */ +@Component +public class HelloRemoteHystrix implements HelloRemote{ + + @Override + public String hello(@RequestParam(value = "name") String name) { + return "hello " +name+", this messge send failed "; + } +} diff --git a/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/resources/application.properties b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/resources/application.properties new file mode 100644 index 0000000..1d270e8 --- /dev/null +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.application.name=spring-cloud-consumer-hystrix +server.port=9001 +feign.hystrix.enabled=true +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/test/java/com/neo/ProducerApplicationTests.java b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/test/java/com/neo/ProducerApplicationTests.java new file mode 100644 index 0000000..677161e --- /dev/null +++ b/spring-cloud-hystrix/spring-cloud-consumer-hystrix/src/test/java/com/neo/ProducerApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerApplicationTests { + + @Test + public void contextLoads() { + } + +}