Skip to content

Commit ab3f930

Browse files
committed
更新
1 parent a6c8a97 commit ab3f930

File tree

11 files changed

+295
-0
lines changed

11 files changed

+295
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.class
2+
3+
# Package Files #
4+
*.jar
5+
*.war
6+
*.ear
7+
8+
# idea Files
9+
.idea
10+
*.iml
11+
target
12+
13+
# log Files
14+
*.log
15+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>eureka-consumer-feign-hystrix</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>eureka-consumer-feign-hystrix</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-feign</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-actuator</artifactId>
42+
</dependency>
43+
</dependencies>
44+
45+
<dependencyManagement>
46+
<dependencies>
47+
<dependency>
48+
<groupId>org.springframework.cloud</groupId>
49+
<artifactId>spring-cloud-dependencies</artifactId>
50+
<version>Dalston.SR1</version>
51+
<type>pom</type>
52+
<scope>import</scope>
53+
</dependency>
54+
</dependencies>
55+
</dependencyManagement>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
7+
8+
@EnableFeignClients
9+
@EnableDiscoveryClient
10+
@SpringBootApplication
11+
public class Application {
12+
13+
public static void main(String[] args) {
14+
new SpringApplicationBuilder(Application.class).web(true).run(args);
15+
}
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.didispace;
2+
3+
import org.springframework.cloud.netflix.feign.FeignClient;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
6+
/**
7+
* @author 翟永超
8+
* @create 2017/6/24.
9+
* @blog http://blog.didispace.com
10+
*/
11+
@FeignClient("eureka-client")
12+
public interface DcClient {
13+
14+
@GetMapping("/dc")
15+
String consumer();
16+
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.didispace;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
/**
8+
* @author 翟永超
9+
* @create 2017/4/15.
10+
* @blog http://blog.didispace.com
11+
*/
12+
@RestController
13+
public class DcController {
14+
15+
@Autowired
16+
DcClient dcClient;
17+
18+
@GetMapping("/consumer")
19+
public String dc() {
20+
return dcClient.consumer();
21+
}
22+
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.application.name=eureka-consumer
2+
server.port=2101
3+
4+
eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/
5+
6+
logging.file=${spring.application.name}.log
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>eureka-consumer-ribbon-hystrix</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>eureka-consumer-ribbon-hystrix</name>
12+
<description>Spring Cloud In Action</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
<relativePath/>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-eureka</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-ribbon</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-actuator</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.cloud</groupId>
45+
<artifactId>spring-cloud-starter-hystrix</artifactId>
46+
</dependency>
47+
</dependencies>
48+
49+
<dependencyManagement>
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.springframework.cloud</groupId>
53+
<artifactId>spring-cloud-dependencies</artifactId>
54+
<version>Dalston.SR1</version>
55+
<type>pom</type>
56+
<scope>import</scope>
57+
</dependency>
58+
</dependencies>
59+
</dependencyManagement>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-maven-plugin</artifactId>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
70+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
8+
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.web.client.RestTemplate;
11+
12+
@EnableCircuitBreaker
13+
@EnableDiscoveryClient
14+
@SpringBootApplication
15+
public class Application {
16+
17+
@Bean
18+
@LoadBalanced
19+
public RestTemplate restTemplate() {
20+
return new RestTemplate();
21+
}
22+
23+
public static void main(String[] args) {
24+
new SpringApplicationBuilder(Application.class).web(true).run(args);
25+
}
26+
27+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.didispace;
2+
3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4+
import com.netflix.ribbon.proxy.annotation.Hystrix;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
import org.springframework.stereotype.Service;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import org.springframework.web.client.RestTemplate;
11+
12+
/**
13+
* @author 翟永超
14+
* @create 2017/4/15.
15+
* @blog http://blog.didispace.com
16+
*/
17+
@RestController
18+
public class DcController {
19+
20+
@Autowired
21+
ConsumerService consumerService;
22+
23+
@GetMapping("/consumer")
24+
public String dc() {
25+
return consumerService.consumer();
26+
}
27+
28+
@Service
29+
class ConsumerService {
30+
31+
@Autowired
32+
RestTemplate restTemplate;
33+
34+
@HystrixCommand(fallbackMethod = "fallback")
35+
public String consumer() {
36+
return restTemplate.getForObject("http://eureka-client/dc", String.class);
37+
}
38+
39+
public String fallback() {
40+
return "fallbck";
41+
}
42+
43+
}
44+
45+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.application.name=eureka-consumer-ribbon-hystrix
2+
server.port=2101
3+
4+
eureka.client.serviceUrl.defaultZone=http://localhost:11001/eureka/
5+
6+
logging.file=${spring.application.name}.log

2-Dalston版教程示例/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<module>config-server-git</module>
2424
<module>config-client</module>
2525

26+
<module>eureka-consumer-ribbon-hystrix</module>
27+
<module>eureka-consumer-feign-hystrix</module>
28+
2629
<module>api-gateway</module>
2730
<module>api-gateway-with-eureka</module>
2831

0 commit comments

Comments
 (0)