Skip to content

Commit 00424d7

Browse files
author
“Rain-with-me”
committed
sentinel的使用,流量控制
1 parent b9da2fa commit 00424d7

File tree

9 files changed

+154
-0
lines changed

9 files changed

+154
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>1-spring-cloud-alibaba-register</artifactId>
7+
<groupId>org.example</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>spring-cloud-alibaba-sentinel-dashboard-8081</artifactId>
13+
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-web</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-devtools</artifactId>
28+
<scope>runtime</scope>
29+
<optional>true</optional>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.projectlombok</groupId>
33+
<artifactId>lombok</artifactId>
34+
<optional>true</optional>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.alibaba.cloud</groupId>
44+
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.lu.sentinel;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* @Author: 雨同我
8+
* @Description:
9+
* @DateTime: 2022/9/30 17:34
10+
**/
11+
@SpringBootApplication
12+
public class SentinelApplication {
13+
public static void main(String[] args) {
14+
SpringApplication.run(SentinelApplication.class,args);
15+
}
16+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.lu.sentinel.controller;
2+
3+
import com.lu.sentinel.service.TestService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
9+
@RestController
10+
public class TestController {
11+
12+
13+
@Autowired
14+
private TestService testService;
15+
16+
/**
17+
* @Description: 测试限流QBS
18+
* QPS(Queries-per-second,每秒钟的请求数量):当调用该api的QPS达到阈值的时候,进行限流;
19+
* @Author: 雨同我
20+
* @DateTime: 2022/9/30 17:51
21+
*/
22+
@GetMapping("test-qps")
23+
public String test() throws InterruptedException {
24+
// TimeUnit.SECONDS.sleep(1);
25+
return "test";
26+
}
27+
28+
/**
29+
* @Description: 测试关联
30+
* @Author: 雨同我
31+
* @DateTime: 2022/10/2 16:02
32+
*/
33+
@GetMapping("link-1")
34+
public String link_1() {
35+
return "link-1"+testService.chainPath();
36+
}
37+
@GetMapping("link-2")
38+
public String link_2() {
39+
return "link-2"+testService.chainPath();
40+
}
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.lu.sentinel.service;
2+
3+
import com.alibaba.csp.sentinel.annotation.SentinelResource;
4+
import org.springframework.stereotype.Service;
5+
6+
/**
7+
* @Author: 雨同我
8+
* @Description:
9+
* @DateTime: 2022/10/2 16:31
10+
**/
11+
@Service
12+
public class TestService {
13+
@SentinelResource("/chain-path")
14+
public String chainPath(){
15+
return "chain-path";
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
port: 8081
3+
spring:
4+
application:
5+
name: sentinel-server
6+
cloud:
7+
sentinel:
8+
transport:
9+
dashboard: localhost:8080
10+
# sentinel客户端和控制台通信的端口,默认为8719,如果这个端口已经被占用
11+
#,那么sentinel会自动从8719开始依次+1扫描,直到找到未被占用的端口。
12+
port: 8790
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
port: 8081
3+
spring:
4+
application:
5+
name: sentinel-server
6+
cloud:
7+
sentinel:
8+
transport:
9+
dashboard: localhost:8080
10+
# sentinel客户端和控制台通信的端口,默认为8719,如果这个端口已经被占用
11+
#,那么sentinel会自动从8719开始依次+1扫描,直到找到未被占用的端口。
12+
port: 8790

0 commit comments

Comments
 (0)