当前位置:网站首页>微服务组件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" }
边栏推荐
- Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
- Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
- [UE4] brush Arctic pack high quality Arctic terrain pack
- An example of HP array card troubleshooting
- 自动渗透测试工具核心功能简述
- Deops入门
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
- Graduation summary
- Where is the database account used when running SQL tasks in data warehouse tasks configured
- PS screen printing brush 131, many illustrators have followed suit
猜你喜欢

IntelliJ 2021.3 short command line when running applications

Tensorboard quick start (pytoch uses tensorboard)

POM in idea XML graying solution

QT学习日记9——对话框

Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code

Deops入门

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge

Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13

Implementation of Tetris in C language
随机推荐
PR second time
Enterprise custom form engine solution (XI) -- form rule engine 1
PS screen printing brush 131, many illustrators have followed suit
Leetcode Valentine's Day Special - looking for a single dog
Managing multiple selections with MVVM - managing multiple selections with MVVM
Web-ui automated testing - the most complete element positioning method
[RT thread] NXP rt10xx device driver framework -- pin construction and use
How to purchase Google colab members in China
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Interviewer: why is the value nil not equal to nil?
QT learning diary 9 - dialog box
Kubernetes resource object introduction and common commands (4)
Notes on problems -- watching videos on edge will make the screen green
Servlet specification Part II
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
Implementation of Tetris in C language
Where is the database account used when running SQL tasks in data warehouse tasks configured
ES6类的继承
IntelliJ 2021.3 short command line when running applications
