Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddb61fd

Browse files
添加 hystrix 和 Zipkin 支持
1 parent cf70521 commit ddb61fd

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

‎eurekaservice/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
<groupId>org.springframework.boot</groupId>
2525
<artifactId>spring-boot-starter-web</artifactId>
2626
</dependency>
27+
28+
<!-- Zipkin -->
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-starter-zipkin</artifactId>
32+
</dependency>
33+
2734
</dependencies>
2835

2936
</project>
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
server:
2-
port: 8081
2+
port: 8082
33
# servlet:
44
# context-path: /eurekaService
55

66
spring:
77
application:
88
name: eureka-service
9+
zipkin:
10+
base-url: http://localhost:9411
911

1012
eureka:
1113
client:
1214
service-url:
1315
defaultZone: http://localhost:8761/eureka/
1416
# instance:
1517
# status-page-url: ${server.servlet.context-path}/info
16-
# health-check-url-path: ${server.servlet.context-path}/health
18+
# health-check-url-path: ${server.servlet.context-path}/health
19+

‎serviceribbon/pom.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,17 @@
2929
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
3030
</dependency>
3131

32+
<!-- hystrix -->
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
36+
</dependency>
37+
38+
<!-- Zipkin -->
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-starter-zipkin</artifactId>
42+
</dependency>
43+
3244
</dependencies>
3345
</project>

‎serviceribbon/src/main/java/com/example/ServiceRibbonApplication.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
88
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
99
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
10+
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
1011
import org.springframework.context.annotation.Bean;
1112
import org.springframework.web.bind.annotation.GetMapping;
1213
import org.springframework.web.bind.annotation.RequestParam;
@@ -15,7 +16,8 @@
1516

1617
@SpringBootApplication
1718
@EnableDiscoveryClient
18-
@EnableEurekaClient
19+
@EnableEurekaClient
20+
@EnableHystrix
1921
@RestController
2022
public class ServiceRibbonApplication {
2123

‎serviceribbon/src/main/java/com/example/service/HelloService.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.service;
22

3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
34
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.stereotype.Service;
56
import org.springframework.web.client.RestTemplate;
@@ -10,7 +11,12 @@ public class HelloService {
1011
@Autowired
1112
RestTemplate restTemplate;
1213

14+
@HystrixCommand(fallbackMethod = "hiError")
1315
public String hi(String name) {
1416
return restTemplate.getForObject("http://EUREKA-SERVICE/hi?name=" + name, String.class);
1517
}
18+
19+
public String hiError(String name) {
20+
return "sorry, service has a error.";
21+
}
1622
}

‎serviceribbon/src/main/resources/application.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ server:
77
port: 8181
88
spring:
99
application:
10-
name: service-ribbon
10+
name: service-ribbon
11+
zipkin:
12+
base-url: http://localhost:9411

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /