当前位置:网站首页>微服务组件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" }
边栏推荐
- Notes on problems -- watching videos on edge will make the screen green
- 问题随记 —— 在 edge 上看视频会绿屏
- 远程办公工具分享|社区征文
- AcWing 3438. 数制转换
- POM in idea XML graying solution
- SWM32系列教程4-端口映射及串口应用
- Implementation of Tetris in C language
- 国内如何购买Google Colab会员
- Simple configuration of postfix server
- Leetcode Valentine's Day Special - looking for a single dog
猜你喜欢

kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)

Interviewer: why is the value nil not equal to nil?

Type conversion, variable

The third day of writing C language by Yabo people

Getting started with deops

PS screen printing brush 131, many illustrators have followed suit

Applet setting multi account debugging

Embedded-c language-7

Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing

Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
随机推荐
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
1146_ SiCp learning notes_ exponentiation
聊聊支付流程的设计与实现逻辑
[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
问题随记 —— 在 edge 上看视频会绿屏
TCP拥塞控制详解 | 3. 设计空间
自动渗透测试工具核心功能简述
Notes on problems -- watching videos on edge will make the screen green
Managing multiple selections with MVVM - managing multiple selections with MVVM
Basic grammar of interview (Part 2)
How to purchase Google colab members in China
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
c# .net 工具生态
Analyse ArrayList 3: suppression d'éléments
List of financial products in 2022
Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
Applet setting multi account debugging
Detailed explanation of common network attacks
The third day of writing C language by Yabo people
