当前位置:网站首页>微服务组件Sentinel控制台调用
微服务组件Sentinel控制台调用
2022-07-03 17:39:00 【kjshuan】
02微服务组件Sentinel (控制台版)
第一步进入linux配置
启动控制台命令 (注意先把文件拖入linux下的opt)
#1 打开编辑文件 vim dashboard.sh #复制下面的内容 账号cm 密码ok(注意 - 有可能要自己手动打) java -Dserver.port=8858 -Dsentinel.dashboard.auth.username=cm -Dsentinel.dashboard.auth.password=ok -jar /opt/sentinel-dashboard-1.8.1.jar #2 授权文件名 chmod 777 dashboard.sh ls ./dashboard.sh cat dashboard.sh ls /opt/ #3 浏览器启动(地址输入自己的) http://192.168.64.200:8858/#/login #4 账号cm 密码ok
显示上面内容成功进入!!!
Sentinel 会在客户端首次调用的时候进行初始化,开始向控制台发送心跳包,所以要确保客户端有访问量;
Spring Cloud Alibaba整合Sentinel
第一步 配置pom
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
第二步配置controller
@RestController @RequestMapping("/nssent") public class InitCtrl { @RequestMapping("/init") public String sayHello(){ return "Hello World"; } }
第三步配置yml
server: port: 12005 spring: application: name: nessentinelctl cloud: sentinel: transport: dashboard: 192.168.64.200:8858
第四步启动浏览器输入
http://localhost:12005/nssent/init #刷新几次 在进入下面地址 http://192.168.64.200:8858/#/dashboard
第五步实现流控
#1 在controller添加代码 自定义流控提示
@RestController @RequestMapping("/nssent") public class InitCtrl { @RequestMapping("/init") @SentinelResource(value = "it",blockHandler = "ctlHandler") public String sayHello(){ return "Hello World"; } public String ctlHandler(BlockException ex){ return "你被流控了o(╥﹏╥)o"; } }
安装jmeter(压力测试)
点击jemter.bat
java代码实现代替jemeter测试(纯代码版)
#第一步导入pom依赖
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version> </dependency>
#第二步编写代码
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * Hello world! * */ public class App { public static void main( String[] args ) { //创建一个线程池 默认10个线程 ExecutorService pool = Executors.newFixedThreadPool(10); //for循环执行10次 for (int i = 0; i < 10; i++) { pool.execute(()->{ try { CloseableHttpClient chc= HttpClients.createDefault(); HttpGet get = new HttpGet("http://localhost:12005/nssent/init"); CloseableHttpResponse response= chc.execute(get); System.out.println( Thread.currentThread().getName()+"--------->"+ EntityUtils.toString(response.getEntity())); } catch (IOException e) { throw new RuntimeException(e); } }); } } }
-------------项目 编写接口-------------(拓展知识 与sentinel无关)
get长度 255字节 2048字符 post 2g 理论没限制
{ "high":100, "weight":60, "scene-manager":"2022-SBZL-05966", "indate":"2022-03-12", "range":"2.6-60" }
边栏推荐
- Comparison of kotlin collaboration + retro build network request schemes
- Draw some simple graphics with MFC
- 互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
- A day's work list of an ordinary programmer
- [RT thread] NXP rt10xx device driver framework -- Audio construction and use
- Apache service suspended asynchronous acceptex failed
- Basic grammar of interview (Part 2)
- Type conversion, variable
- Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
- [combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
猜你喜欢
UE4 official charging resources, with a total price of several thousand
Leetcode 669 pruning binary search tree -- recursive method and iterative method
vs2013已阻止安装程序,需安装IE10
Test your trained model
kubernetes资源对象介绍及常用命令(四)
STM32 realizes 74HC595 control
Draw some simple graphics with MFC
【JokerのZYNQ7020】DDS_ Compiler。
鸿蒙第四次培训
How to purchase Google colab members in China
随机推荐
远程办公工具分享|社区征文
QT adjust win screen brightness and sound size
1164 Good in C
How to purchase Google colab members in China
[mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
STM32 realizes 74HC595 control
link preload prefetch
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
TCP congestion control details | 3 design space
UE4 official charging resources, with a total price of several thousand
STM32实现74HC595控制
Kotlin learning quick start (7) -- wonderful use of expansion
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
How SVN views modified file records
[combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
Graduation summary
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
First day of rhcsa study
Implementation of Tetris in C language
毕业总结