Skip to content

Commit 85247a7

Browse files
author
zhangyixin
committed
fix
1 parent 0b90b13 commit 85247a7

File tree

13 files changed

+128
-1
lines changed

13 files changed

+128
-1
lines changed

consulService1/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ dependencies {
22
implementation 'org.springframework.boot:spring-boot-starter-web'
33
implementation 'org.springframework.boot:spring-boot-starter-actuator'
44
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
5+
implementation 'org.springframework.cloud:spring-cloud-starter-hystrix:1.4.7.RELEASE'
6+
implementation 'org.springframework.cloud:spring-cloud-starter-feign:1.4.6.RELEASE'
57
}
68

consulService1/src/main/java/com/xyz/ConsulClientApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
56
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
8+
import org.springframework.cloud.openfeign.EnableFeignClients;
69

10+
@EnableFeignClients
11+
@EnableHystrix
12+
@EnableCircuitBreaker
713
@EnableDiscoveryClient
814
@SpringBootApplication
915
public class ConsulClientApplication {

consulService1/src/main/java/com/xyz/controller/HelloController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.xyz.controller;
22

3+
import com.xyz.service.ConsulService2;
4+
import org.springframework.beans.factory.annotation.Autowired;
35
import org.springframework.web.bind.annotation.RequestMapping;
46
import org.springframework.web.bind.annotation.RequestMethod;
57
import org.springframework.web.bind.annotation.RestController;
@@ -9,11 +11,17 @@
911

1012
@RestController
1113
public class HelloController {
12-
14+
@Autowired
15+
private ConsulService2 consulService2;
1316
@RequestMapping(method = RequestMethod.GET, value = "/hello")
1417
public Map<String, String> hello() {
1518
Map<String, String> map = new HashMap<>();
1619
map.put("text", "aaaaaaaaaa");
1720
return map;
1821
}
22+
23+
@RequestMapping(method = RequestMethod.GET, value = "/returnFromService2")
24+
public Map<String, String> returnFromService2() {
25+
return consulService2.returnFromService2();
26+
}
1927
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xyz.service;
2+
3+
import org.springframework.cloud.openfeign.FeignClient;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
7+
import java.util.Map;
8+
9+
@FeignClient(name = "consul-client", fallback = ConsulService2Hystrix.class)
10+
public interface ConsulService2 {
11+
12+
@RequestMapping(method = RequestMethod.GET, value = "/returnFromService2")
13+
Map<String, String> returnFromService2();
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.xyz.service;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
@Component
8+
public class ConsulService2Hystrix implements ConsulService2{
9+
@Override
10+
public Map<String, String> returnFromService2() {
11+
Map<String, String> map = new HashMap<>();
12+
map.put("text", "returnFromService2 eeeeeeeeeeeeeeeeeeeeeee");
13+
return map;
14+
}
15+
}

consulService1/src/main/resources/application.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
server:
22
port: 8001
3+
management:
4+
endpoints:
5+
web:
6+
exposure:
7+
include: '*'
8+
feign:
9+
hystrix:
10+
enabled: true
311
spring:
412
cloud:
513
consul:

consulService2/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ dependencies {
22
implementation 'org.springframework.boot:spring-boot-starter-web'
33
implementation 'org.springframework.boot:spring-boot-starter-actuator'
44
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
5+
implementation 'org.springframework.cloud:spring-cloud-starter-hystrix:1.4.7.RELEASE'
56
}

consulService2/src/main/java/com/xyz/controller/HelloController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ public Map<String, String> hello() {
1616
map.put("text", "bbbbbbbbbbbb");
1717
return map;
1818
}
19+
20+
@RequestMapping(method = RequestMethod.GET, value = "/returnFromService2")
21+
public Map<String, String> hello2() {
22+
Map<String, String> map = new HashMap<>();
23+
map.put("text", "returnFromService2");
24+
return map;
25+
}
1926
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ include 'base'
2121
include 'gateway'
2222
include 'consulService1'
2323
include 'consulService2'
24+
include 'turbineDashboard'
2425

turbineDashboard/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencies {
2+
implementation "org.springframework.boot:spring-boot-starter-web"
3+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
4+
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
5+
implementation 'org.springframework.cloud:spring-cloud-netflix-turbine'
6+
implementation 'org.springframework.cloud:spring-cloud-starter-hystrix:1.4.7.RELEASE'
7+
implementation 'org.springframework.cloud:spring-cloud-starter-hystrix-dashboard:1.4.7.RELEASE'
8+
}

0 commit comments

Comments
 (0)