Skip to content

Commit bac74ce

Browse files
author
feiweiwei
committed
add hystrix sample
0 parents  commit bac74ce

13 files changed

Lines changed: 400 additions & 0 deletions

File tree

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Intellij
2+
.idea/
3+
*.iml
4+
*.iws
5+
6+
# Mac
7+
.DS_Store
8+
9+
# Maven
10+
log/
11+
target/

hystrixclient/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>hystrix-client</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-hystrix</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-actuator</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
38+
</dependency>
39+
</dependencies>
40+
41+
<!-- 引入spring cloud的依赖 -->
42+
<dependencyManagement>
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-dependencies</artifactId>
47+
<version>Camden.SR4</version>
48+
<type>pom</type>
49+
<scope>import</scope>
50+
</dependency>
51+
</dependencies>
52+
</dependencyManagement>
53+
54+
<!-- 添加spring-boot的maven插件 -->
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-maven-plugin</artifactId>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.monkey01.hystrixclient;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6+
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
7+
8+
/**
9+
* @Author: feiweiwei
10+
* @Description:
11+
* @Created Date: 10:58 17/9/21.
12+
* @Modify by:
13+
*/
14+
@SpringBootApplication
15+
@EnableHystrixDashboard
16+
@EnableCircuitBreaker
17+
public class Application {
18+
public static void main(String[] args) {
19+
SpringApplication.run(Application.class, args);
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.monkey01.hystrixclient.controller;
2+
3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
/**
10+
* @Author: feiweiwei
11+
* @Description:
12+
* @Created Date: 11:00 17/9/21.
13+
* @Modify by:
14+
*/
15+
@RestController
16+
public class TestController {
17+
@HystrixCommand(fallbackMethod = "error", commandProperties = {
18+
@HystrixProperty(name="execution.isolation.strategy", value = "THREAD"),
19+
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "4000"),
20+
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
21+
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "40")
22+
}, threadPoolProperties = {
23+
@HystrixProperty(name = "coreSize", value = "1"),
24+
// @HystrixProperty(name = "maximumSize", value = "5"),
25+
@HystrixProperty(name = "maxQueueSize", value = "10"),
26+
@HystrixProperty(name = "keepAliveTimeMinutes", value = "1000"),
27+
@HystrixProperty(name = "queueSizeRejectionThreshold", value = "8"),
28+
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
29+
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
30+
})
31+
@RequestMapping(value = "/hello", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
32+
public String hello(){
33+
return "hello hystrix!";
34+
}
35+
36+
public String error() {
37+
return "hello error!";
38+
}
39+
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server:
2+
port: 8081
3+
spring:
4+
application:
5+
name: hystrix-client
6+
eureka:
7+
client:
8+
serviceUrl:
9+
defaultZone: http://localhost:8761/eureka/

hystrixclientrabbitmq/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>hystrix-client-rabbitmq</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-hystrix</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-stream-rabbit</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-dashboard</artifactId>
46+
</dependency>
47+
</dependencies>
48+
49+
<!-- 引入spring cloud的依赖 -->
50+
<dependencyManagement>
51+
<dependencies>
52+
<dependency>
53+
<groupId>org.springframework.cloud</groupId>
54+
<artifactId>spring-cloud-dependencies</artifactId>
55+
<version>Camden.SR4</version>
56+
<type>pom</type>
57+
<scope>import</scope>
58+
</dependency>
59+
</dependencies>
60+
</dependencyManagement>
61+
62+
<!-- 添加spring-boot的maven插件 -->
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-maven-plugin</artifactId>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.monkey01.hystrixmq;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6+
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
7+
8+
/**
9+
* @Author: feiweiwei
10+
* @Description:
11+
* @Created Date: 15:39 17/9/21.
12+
* @Modify by:
13+
*/
14+
@SpringBootApplication
15+
@EnableHystrixDashboard
16+
@EnableCircuitBreaker
17+
public class Application {
18+
public static void main(String[] args) {
19+
SpringApplication.run(Application.class, args);
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.monkey01.hystrixmq.controller;
2+
3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
/**
10+
* @Author: feiweiwei
11+
* @Description:
12+
* @Created Date: 11:00 17/9/21.
13+
* @Modify by:
14+
*/
15+
@RestController
16+
public class TestController {
17+
@HystrixCommand(fallbackMethod = "error", commandProperties = {
18+
@HystrixProperty(name="execution.isolation.strategy", value = "THREAD"),
19+
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "4000"),
20+
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
21+
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "40")
22+
}, threadPoolProperties = {
23+
@HystrixProperty(name = "coreSize", value = "1"),
24+
// @HystrixProperty(name = "maximumSize", value = "5"),
25+
@HystrixProperty(name = "maxQueueSize", value = "10"),
26+
@HystrixProperty(name = "keepAliveTimeMinutes", value = "1000"),
27+
@HystrixProperty(name = "queueSizeRejectionThreshold", value = "8"),
28+
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
29+
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
30+
})
31+
@RequestMapping(value = "/hello", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
32+
public String hello(){
33+
return "hello hystrix!";
34+
}
35+
36+
public String error() {
37+
return "hello error!";
38+
}
39+
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
application:
3+
name: hystrix-mq
4+
rabbitmq:
5+
host: 10.132.33.43
6+
port: 5672
7+
username: admin
8+
password: admin
9+
10+
server:
11+
port: 8081

hystrixturbine/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
<groupId>com.monkey01.springcloud</groupId>
6+
<artifactId>hystrix-turbine</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<!-- 引入spring boot的依赖 -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.7.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-turbine-stream</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<!-- 引入spring cloud的依赖 -->
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-dependencies</artifactId>
39+
<version>Camden.SR4</version>
40+
<type>pom</type>
41+
<scope>import</scope>
42+
</dependency>
43+
</dependencies>
44+
</dependencyManagement>
45+
46+
<!-- 添加spring-boot的maven插件 -->
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>

0 commit comments

Comments
 (0)