一,下載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"; }
五,訪問應用接口,然后刷新控制台,就可以看到應用的訪問信息了