From febab47c56414fd96f7fdf0ced3fe69c7ab2400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Thu, 2 Jun 2016 13:06:04 +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=BA=8C=EF=BC=89?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=9C=8D=E5=8A=A1=E6=B6=88=E8=B4=B9=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chapter9-1-2/eureka-ribbon/pom.xml | 68 +++++++++++++++++++ .../java/com/didispace/RibbonApplication.java | 24 +++++++ .../com/didispace/web/ConsumerController.java | 21 ++++++ .../src/main/resources/application.properties | 5 ++ 4 files changed, 118 insertions(+) create mode 100644 Chapter9-1-2/eureka-ribbon/pom.xml create mode 100755 Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/RibbonApplication.java create mode 100755 Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java create mode 100755 Chapter9-1-2/eureka-ribbon/src/main/resources/application.properties diff --git a/Chapter9-1-2/eureka-ribbon/pom.xml b/Chapter9-1-2/eureka-ribbon/pom.xml new file mode 100644 index 0000000..3208a14 --- /dev/null +++ b/Chapter9-1-2/eureka-ribbon/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.didispace + eureka-ribbon + 1.0.0 + jar + + eureka-ribbon + Spring Cloud project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.5.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-ribbon + + + 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-ribbon/src/main/java/com/didispace/RibbonApplication.java b/Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/RibbonApplication.java new file mode 100755 index 0000000..6a4a755 --- /dev/null +++ b/Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/RibbonApplication.java @@ -0,0 +1,24 @@ +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.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication +@EnableDiscoveryClient +public class RibbonApplication { + + @Bean + @LoadBalanced + RestTemplate restTemplate() { + return new RestTemplate(); + } + + public static void main(String[] args) { + SpringApplication.run(RibbonApplication.class, args); + } + +} diff --git a/Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java b/Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java new file mode 100755 index 0000000..55af600 --- /dev/null +++ b/Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java @@ -0,0 +1,21 @@ +package com.didispace.web; + +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; +import org.springframework.web.client.RestTemplate; + +@RestController +public class ConsumerController { + + @Autowired + RestTemplate restTemplate; + + @RequestMapping(value = "/add", method = RequestMethod.GET) + public String add() { + return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a=10&b=20", String.class).getBody(); + } + + +} \ No newline at end of file diff --git a/Chapter9-1-2/eureka-ribbon/src/main/resources/application.properties b/Chapter9-1-2/eureka-ribbon/src/main/resources/application.properties new file mode 100755 index 0000000..d819480 --- /dev/null +++ b/Chapter9-1-2/eureka-ribbon/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.application.name=ribbon-consumer +server.port=3333 + +eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ +