File tree Expand file tree Collapse file tree 8 files changed +77
-3
lines changed
api-gateway/src/main/resources
eureka-order/src/main/java/com/coderqian/eurekaorder/controller
java/com/coderqian/feginserver Expand file tree Collapse file tree 8 files changed +77
-3
lines changed Original file line number Diff line number Diff line change @@ -15,5 +15,7 @@ zuul.ignoredServices='*'
1515zuul.routes.api-c.path =/feign/**
1616zuul.routes.api-c.serviceId =feign-server
1717
18+ # 请求连接的超时时间
1819# ribbon.ConnectTimeout=6000
20+ # 请求处理的超时时间
1921# ribbon.ReadTimeout=6000
Original file line number Diff line number Diff line change 44import io .swagger .annotations .ApiOperation ;
55import org .springframework .web .bind .annotation .RequestMapping ;
66import org .springframework .web .bind .annotation .RequestMethod ;
7+ import org .springframework .web .bind .annotation .RequestParam ;
78import org .springframework .web .bind .annotation .RestController ;
89
910/**
@@ -19,7 +20,7 @@ public class TestController {
1920
2021 @ ApiOperation (value = "返回用户输入的结果" , notes = "返回用户输入的结果" )
2122 @ RequestMapping (value = "/result" , method = RequestMethod .GET )
22- public String test (String text ) {
23+ public String test (@ RequestParam ( value = "text" ) String text ) {
2324 return text ;
2425 }
2526}
Original file line number Diff line number Diff line change 3737 <artifactId >spring-cloud-starter-feign</artifactId >
3838 </dependency >
3939
40+ <dependency >
41+ <groupId >org.springframework.cloud</groupId >
42+ <artifactId >spring-cloud-starter-hystrix</artifactId >
43+ </dependency >
44+
45+ <dependency >
46+ <groupId >org.springframework.cloud</groupId >
47+ <artifactId >spring-cloud-starter-hystrix-dashboard</artifactId >
48+ </dependency >
49+
4050 <dependency >
4151 <groupId >org.springframework.cloud</groupId >
4252 <artifactId >spring-cloud-starter-eureka</artifactId >
Original file line number Diff line number Diff line change 22
33import org .springframework .boot .SpringApplication ;
44import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cloud .client .circuitbreaker .EnableCircuitBreaker ;
56import org .springframework .cloud .netflix .eureka .EnableEurekaClient ;
67import org .springframework .cloud .netflix .feign .EnableFeignClients ;
8+ import org .springframework .cloud .netflix .hystrix .dashboard .EnableHystrixDashboard ;
79
810
911@ SpringBootApplication
1012@ EnableEurekaClient
1113@ EnableFeignClients
14+ @ EnableHystrixDashboard
15+ @ EnableCircuitBreaker
1216public class FeignServerApplication {
1317
1418 public static void main (String [] args ) {
Original file line number Diff line number Diff line change 1+ package com .coderqian .feginserver .configuration ;
2+
3+ import com .netflix .hystrix .HystrixCommand ;
4+ import feign .Feign ;
5+ import feign .hystrix .HystrixFeign ;
6+ import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
7+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
8+ import org .springframework .context .annotation .Bean ;
9+ import org .springframework .context .annotation .Configuration ;
10+ import org .springframework .context .annotation .Scope ;
11+
12+ /**
13+ * @author qianliqing
14+ * @date 2018-10-16 下午5:29
15+ 16+ */
17+
18+ //@Configuration
19+ @ ConditionalOnClass ({HystrixCommand .class , HystrixFeign .class })
20+ public class FeignServerConfiguration {
21+
22+ @ Bean
23+ @ Scope ("prototype" )
24+ @ ConditionalOnProperty (name = "feign.hystrix.enabled" , matchIfMissing = true )
25+ public Feign .Builder feignBuilder () {
26+ return Feign .builder ();
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package com .coderqian .feginserver .configuration .fallback ;
2+
3+ import com .coderqian .feginserver .service .TestCustomerService ;
4+ import org .springframework .stereotype .Component ;
5+
6+ /**
7+ * @author qianliqing
8+ * @date 2018-10-16 下午5:08
9+ 10+ */
11+
12+ @ Component
13+ public class HystrixClientFallback implements TestCustomerService {
14+
15+ @ Override
16+ public String testCustomer (String text ) {
17+ return "失败:" + text ;
18+ }
19+ }
Original file line number Diff line number Diff line change 11package com .coderqian .feginserver .service ;
22
3+ import com .coderqian .feginserver .configuration .fallback .HystrixClientFallback ;
34import org .springframework .cloud .netflix .feign .FeignClient ;
5+ import org .springframework .stereotype .Service ;
46import org .springframework .web .bind .annotation .RequestMapping ;
57import org .springframework .web .bind .annotation .RequestMethod ;
68import org .springframework .web .bind .annotation .RequestParam ;
11131214 */
1315
14- @ FeignClient (value = "eureka-customer" )
16+ @ FeignClient (value = "eureka-customer" , fallback = HystrixClientFallback .class )
17+ @ Service
1518public interface TestCustomerService {
1619
1720 @ RequestMapping (value = "/test/result" , method = RequestMethod .GET )
Original file line number Diff line number Diff line change 11spring.application.name =feign-server
22server.port =8765
3- eureka.client.service-url.defaultZone =http://127.0.0.1:8761/eureka
3+ eureka.client.service-url.defaultZone =http://127.0.0.1:8761/eureka
4+
5+ feign.hystrix.enabled =true
6+
7+ # 请求处理的超时时间
8+ # ribbon.ReadTimeout=120000
9+ # 请求连接的超时时间
10+ # ribbon.ConnectTimeout=30000
You can’t perform that action at this time.
0 commit comments