diff --git a/Chapter9-1-2/eureka-feign/pom.xml b/Chapter9-1-2/eureka-feign/pom.xml new file mode 100644 index 0000000..d7c050d --- /dev/null +++ b/Chapter9-1-2/eureka-feign/pom.xml @@ -0,0 +1,68 @@ + + + 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-2/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java b/Chapter9-1-2/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java new file mode 100644 index 0000000..c804ffa --- /dev/null +++ b/Chapter9-1-2/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("compute-service") +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-2/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java b/Chapter9-1-2/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java new file mode 100755 index 0000000..7876fbf --- /dev/null +++ b/Chapter9-1-2/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 diff --git a/Chapter9-1-2/eureka-feign/src/main/resources/application.properties b/Chapter9-1-2/eureka-feign/src/main/resources/application.properties new file mode 100755 index 0000000..d9d2128 --- /dev/null +++ b/Chapter9-1-2/eureka-feign/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.application.name=feign-consumer +server.port=3333 + +eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ +