sentinel控制台的使用

一,下载sentinel控制台:sentinel-dashboard-1.7.0.jar , 注 1.7.1版本控制台与最新的sentinel有冲突,会报invalid type错误

二,启动sentinel控制台

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.7.0.jar

三,打开网址 http://localhost:8080, 登录账号和密码都是sentinel

四,应用接入sentinel控制台

  1,添加pom依赖

     <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

  2,添加配置项

sentinel:
      transport:
        dashboard: localhost:8080

  3,给接口添加注解

@GetMapping("/test")
    @SentinelResource(value = "demo_test", blockHandler = "block", fallback = "fallback") //blockHandlerClass = "", fallbackClass = ""不指定就是本类
public String test(){ return "test, name:" + userClient.getName() + ", address:" + userClient.getAddress() + "order_id:" + orderClient.getId() + "order_price:" + orderClient.getPrice(); } public String block(){ return "blocked"; } public String fallback(){ return "fallbacked"; }

五,访问应用接口,然后刷新控制台,就可以看到应用的访问信息了

猜你喜欢

转载自www.cnblogs.com/dongbo/p/12212718.html
今日推荐