From c2ee5eb1eee31e77617303ef9381536f23df0117 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sat, 25 Jun 2016 22:25:19 +0800 Subject: [PATCH] =?UTF-8?q?Spring=20Cloud=E6=9E=84=E5=BB=BA=E5=BE=AE?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=9E=B6=E6=9E=84=EF=BC=88=E4=B8=89=EF=BC=89?= =?UTF-8?q?=E6=96=AD=E8=B7=AF=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chapter9-1-3/eureka-feign/pom.xml | 72 +++++++++++++++++++ .../java/com/didispace/FeignApplication.java | 17 +++++ .../com/didispace/service/ComputeClient.java | 14 ++++ .../service/ComputeClientHystrix.java | 14 ++++ .../com/didispace/web/ConsumerController.java | 20 ++++++ 5 files changed, 137 insertions(+) create mode 100644 Chapter9-1-3/eureka-feign/pom.xml create mode 100644 Chapter9-1-3/eureka-feign/src/main/java/com/didispace/FeignApplication.java create mode 100644 Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java create mode 100644 Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClientHystrix.java create mode 100644 Chapter9-1-3/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java diff --git a/Chapter9-1-3/eureka-feign/pom.xml b/Chapter9-1-3/eureka-feign/pom.xml new file mode 100644 index 0000000..4972159 --- /dev/null +++ b/Chapter9-1-3/eureka-feign/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.didispace + eureka-feign + 1.0.0 + jar + + eureka-feign + Spring Cloud project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.5.RELEASE + + + + + UTF-8 + 1.8 + + + + + + + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.RELEASE + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/FeignApplication.java b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/FeignApplication.java new file mode 100644 index 0000000..9e1228f --- /dev/null +++ b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/FeignApplication.java @@ -0,0 +1,17 @@ +package com.didispace; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class FeignApplication { + + public static void main(String[] args) { + SpringApplication.run(FeignApplication.class, args); + } + +} diff --git a/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java new file mode 100644 index 0000000..41cae97 --- /dev/null +++ b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java @@ -0,0 +1,14 @@ +package com.didispace.service; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(value = "compute-service", fallback = ComputeClientHystrix.class) +public interface ComputeClient { + + @RequestMapping(method = RequestMethod.GET, value = "/add") + Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b); + +} \ No newline at end of file diff --git a/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClientHystrix.java b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClientHystrix.java new file mode 100644 index 0000000..541aa84 --- /dev/null +++ b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClientHystrix.java @@ -0,0 +1,14 @@ +package com.didispace.service; + +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +@Component +public class ComputeClientHystrix implements ComputeClient { + + @Override + public Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b) { + return -9999; + } + +} \ No newline at end of file diff --git a/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java new file mode 100644 index 0000000..7876fbf --- /dev/null +++ b/Chapter9-1-3/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java @@ -0,0 +1,20 @@ +package com.didispace.web; + +import com.didispace.service.ComputeClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ConsumerController { + + @Autowired + ComputeClient computeClient; + + @RequestMapping(value = "/add", method = RequestMethod.GET) + public Integer add() { + return computeClient.add(10, 20); + } + +} \ No newline at end of file