Skip to content

Commit ded4b48

Browse files
启动服务消费者feign中的断路器hystrix
1 parent 1e395e8 commit ded4b48

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.demo.feignInterface;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
/**
6+
* Created by lenovo on 九月
7+
*/
8+
9+
@Component
10+
public class ClientHystrix implements DcClient {
11+
@Override
12+
public String consumer() {
13+
return "hystrix";
14+
}
15+
}

eureka-consumer-feign/src/main/java/com/example/demo/feignInterface/DcClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
*/
99

1010
/**
11-
* 使用@FeignClient注解来指定这个接口所要调用的服务名称,
11+
* 使用@FeignClient注解。其中的value指定这个接口所要调用的服务名称,fallback指定hystrix的回调类
1212
* 接口中定义的各个函数使用Spring MVC的注解就可以来绑定服务提供方的REST接口
1313
*/
14-
@FeignClient("eureka-client")
14+
@FeignClient(value = "eureka-client",fallback = ClientHystrix.class)
1515
public interface DcClient {
16-
17-
@GetMapping("/dc")
16+
@GetMapping(value = "/dc")
1817
String consumer();
1918
}

eureka-consumer-feign/src/main/resources/application.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ spring:
22
application:
33
name: eureka-consumer-feign
44

5-
65
server:
76
port: 5555
87

9-
108
eureka:
119
client:
1210
serviceUrl:
1311
defaultZone: http://localhost:1111/eureka/
12+
13+
#启动hystrix
14+
feign:
15+
hystrix:
16+
enabled: true

0 commit comments

Comments
 (0)