Skip to content

Commit 95da1d3

Browse files
committedMar 20, 2020
Spring Cloud Alibaba Sentinel控制台详解
1 parent a90a374 commit 95da1d3

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.5.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>cc.mrbird</groupId>
12+
<artifactId>spring-cloud-alibaba-sentinel-dashboard-guide</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>spring-cloud-alibaba-sentinel-dashboard-guide</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
20+
<com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-web</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.alibaba.cloud</groupId>
30+
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
31+
</dependency>
32+
</dependencies>
33+
34+
<dependencyManagement>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.cloud</groupId>
38+
<artifactId>spring-cloud-dependencies</artifactId>
39+
<version>${spring-cloud.version}</version>
40+
<type>pom</type>
41+
<scope>import</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.alibaba.cloud</groupId>
45+
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
46+
<version>${com-alibaba-cloud.version}</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
</dependencies>
51+
</dependencyManagement>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-maven-plugin</artifactId>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cc.mrbird.sentinel;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringCloudAlibabaSentinelFlowControlApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringCloudAlibabaSentinelFlowControlApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cc.mrbird.sentinel.controller;
2+
3+
import cc.mrbird.sentinel.service.HelloService;
4+
import com.alibaba.csp.sentinel.annotation.SentinelResource;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
/**
12+
* @author MrBird
13+
*/
14+
@RestController
15+
public class TestController {
16+
17+
private Logger log = LoggerFactory.getLogger(this.getClass());
18+
19+
@Autowired
20+
private HelloService helloService;
21+
22+
@GetMapping("test1")
23+
public String test1() {
24+
throw new RuntimeException("服务异常");
25+
// return "test1";
26+
}
27+
28+
@GetMapping("test2")
29+
public String test2() {
30+
return "test2 " + helloService.hello();
31+
}
32+
33+
@GetMapping("buy")
34+
@SentinelResource(value = "buy")
35+
public String buy(String goodName, Integer count) {
36+
return "买" + count + "份" + goodName;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cc.mrbird.sentinel.service;
2+
3+
import com.alibaba.csp.sentinel.annotation.SentinelResource;
4+
import org.springframework.stereotype.Service;
5+
6+
/**
7+
* @author MrBird
8+
*/
9+
@Service
10+
public class HelloService {
11+
12+
@SentinelResource("hello")
13+
public String hello() {
14+
return "hello";
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server:
2+
port: 8081
3+
spring:
4+
application:
5+
name: my-project
6+
cloud:
7+
sentinel:
8+
transport:
9+
dashboard: localhost:8080
10+
port: 8719
11+
web-context-unify: false

0 commit comments

Comments
 (0)
Please sign in to comment.