提交 8e02153b 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:本地启动nacos

上级 ead9e181
...@@ -84,7 +84,6 @@ ...@@ -84,7 +84,6 @@
<version>1.8.2</version> <version>1.8.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package com.kwan.springcloudalibaba.controller; package com.kwan.springcloudalibaba.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource; import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -15,6 +18,7 @@ import java.util.concurrent.TimeUnit; ...@@ -15,6 +18,7 @@ import java.util.concurrent.TimeUnit;
* @version : 2.2.0 * @version : 2.2.0
* @date : 2023/2/2 17:13 * @date : 2023/2/2 17:13
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/flowLimit") @RequestMapping("/flowLimit")
public class FlowLimitController { public class FlowLimitController {
...@@ -71,4 +75,46 @@ public class FlowLimitController { ...@@ -71,4 +75,46 @@ public class FlowLimitController {
} }
return "------testE"; return "------testE";
} }
/**
* 热点规则
*
* @param p1
* @param p2
* @return
*/
@GetMapping("/testHotKey")
@SentinelResource(value = "testHotKey")
public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
@RequestParam(value = "p2", required = false) String p2) {
return "------testHotKey";
}
@GetMapping("/testHotKey2")
@SentinelResource(value = "testHotKey2", blockHandler = "dealHandler_testHotKey")
public String testHotKey2(@RequestParam(value = "p1", required = false) String p1,
@RequestParam(value = "p2", required = false) String p2) {
log.info("testE 热点参数");
return "------testHotKey2";
}
/**
* 自定义异常
*
* @param p1
* @param p2
* @param exception
* @return
*/
public String dealHandler_testHotKey(String p1, String p2, BlockException exception) {
// 默认 Blocked by Sentinel (flow limiting)
return "-----dealHandler_testHotKey";
}
@GetMapping("/persistent")
public String persistent() {
log.info("persistent 测试持久化");
return "------persistent 测试持久化";
}
} }
\ No newline at end of file
...@@ -11,9 +11,9 @@ spring: ...@@ -11,9 +11,9 @@ spring:
cloud: cloud:
nacos: nacos:
discovery: discovery:
server-addr: http://120.79.36.53:8848 #服务注册地址 server-addr: localhost:8848 #服务注册地址
config: config:
server-addr: http://120.79.36.53:8848 #配置中心地址 server-addr: localhost:8848 #配置中心地址
file-extension: yaml #文件类型 file-extension: yaml #文件类型
group: DEV_GROUP #组别 group: DEV_GROUP #组别
namespace: 4cd9bd32-8f25-45cd-b919-df1a0df146e0 #命名空间 namespace: 4cd9bd32-8f25-45cd-b919-df1a0df146e0 #命名空间
...@@ -22,4 +22,11 @@ spring: ...@@ -22,4 +22,11 @@ spring:
transport: transport:
dashboard: 127.0.0.1:8181 dashboard: 127.0.0.1:8181
port: 8719 #默认端口,如果被占用则从8719依次+1扫描 port: 8719 #默认端口,如果被占用则从8719依次+1扫描
datasource:
ds1:
nacos:
server-addr: localhost:8848
dataId: nacos-server-sentinel-consumer # 微服务名称
groupId: DEFAULT_GROUP
data-type: json
rule-type: flow # 流控规则
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册