当前位置:网站首页>微服务组件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" }
边栏推荐
- Apache service suspended asynchronous acceptex failed
- 自动渗透测试工具核心功能简述
- RedHat 6.2 configuring ZABBIX
- 1164 Good in C
- MinGW compile boost library
- Wechat applet for the first time
- PHP processing - watermark images (text, etc.)
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
- Kubernetes resource object introduction and common commands (4)
- Basic grammar of interview (Part 2)
猜你喜欢

QT learning diary 9 - dialog box

Select 3 fcpx plug-ins. Come and see if you like them

鸿蒙第四次培训

Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method

Implementation of Tetris in C language

聊聊支付流程的设计与实现逻辑

Kubernetes resource object introduction and common commands (III)

1147_ Makefile learning_ Target files and dependent files in makefile

Redis: operation commands for list type data

2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
随机推荐
AcWing 4489. Longest subsequence
Kubernetes resource object introduction and common commands (4)
MySQL grouping query
Test your trained model
PR second time
Tensorboard quick start (pytoch uses tensorboard)
vs2013已阻止安装程序,需安装IE10
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
SWM32系列教程4-端口映射及串口应用
Leetcode540: a single element in an ordered array
Notes on problems -- watching videos on edge will make the screen green
Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
Golang单元测试、Mock测试以及基准测试
TCP congestion control details | 3 design space
Applet setting multi account debugging
