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='*'
15
15
zuul.routes.api-c.path =/feign/**
16
16
zuul.routes.api-c.serviceId =feign-server
17
17
18
+ # 请求连接的超时时间
18
19
# ribbon.ConnectTimeout=6000
20
+ # 请求处理的超时时间
19
21
# ribbon.ReadTimeout=6000
Original file line number Diff line number Diff line change 4
4
import io .swagger .annotations .ApiOperation ;
5
5
import org .springframework .web .bind .annotation .RequestMapping ;
6
6
import org .springframework .web .bind .annotation .RequestMethod ;
7
+ import org .springframework .web .bind .annotation .RequestParam ;
7
8
import org .springframework .web .bind .annotation .RestController ;
8
9
9
10
/**
@@ -19,7 +20,7 @@ public class TestController {
19
20
20
21
@ ApiOperation (value = "返回用户输入的结果" , notes = "返回用户输入的结果" )
21
22
@ RequestMapping (value = "/result" , method = RequestMethod .GET )
22
- public String test (String text ) {
23
+ public String test (@ RequestParam ( value = "text" ) String text ) {
23
24
return text ;
24
25
}
25
26
}
Original file line number Diff line number Diff line change 37
37
<artifactId >spring-cloud-starter-feign</artifactId >
38
38
</dependency >
39
39
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
+
40
50
<dependency >
41
51
<groupId >org.springframework.cloud</groupId >
42
52
<artifactId >spring-cloud-starter-eureka</artifactId >
Original file line number Diff line number Diff line change 2
2
3
3
import org .springframework .boot .SpringApplication ;
4
4
import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
+ import org .springframework .cloud .client .circuitbreaker .EnableCircuitBreaker ;
5
6
import org .springframework .cloud .netflix .eureka .EnableEurekaClient ;
6
7
import org .springframework .cloud .netflix .feign .EnableFeignClients ;
8
+ import org .springframework .cloud .netflix .hystrix .dashboard .EnableHystrixDashboard ;
7
9
8
10
9
11
@ SpringBootApplication
10
12
@ EnableEurekaClient
11
13
@ EnableFeignClients
14
+ @ EnableHystrixDashboard
15
+ @ EnableCircuitBreaker
12
16
public class FeignServerApplication {
13
17
14
18
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 1
1
package com .coderqian .feginserver .service ;
2
2
3
+ import com .coderqian .feginserver .configuration .fallback .HystrixClientFallback ;
3
4
import org .springframework .cloud .netflix .feign .FeignClient ;
5
+ import org .springframework .stereotype .Service ;
4
6
import org .springframework .web .bind .annotation .RequestMapping ;
5
7
import org .springframework .web .bind .annotation .RequestMethod ;
6
8
import org .springframework .web .bind .annotation .RequestParam ;
11
13
12
14
*/
13
15
14
- @ FeignClient (value = "eureka-customer" )
16
+ @ FeignClient (value = "eureka-customer" , fallback = HystrixClientFallback .class )
17
+ @ Service
15
18
public interface TestCustomerService {
16
19
17
20
@ RequestMapping (value = "/test/result" , method = RequestMethod .GET )
Original file line number Diff line number Diff line change 1
1
spring.application.name =feign-server
2
2
server.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