李林超博客
首页
归档
留言
友链
动态
关于
归档
留言
友链
动态
关于
首页
Java
正文
02.Sentinel初始化演示工程
Leefs
2023-01-14 PM
1040℃
0条
[TOC] #### 前言 **准备环境**: + JDK 1.8 + nacos 2.1.0 + sentinel-dashboard 1.8.5 本次演示都是在本地windows系统上进行,只是入门级。 #### 1、启动Nacos服务 + windows系统Nacos启动命令(nacos服务bin目录下) ``` startup.cmd -m standalone ``` #### 2、新建Module + 名称:**sentinel-service-demo01** ![02.Sentinel初始化演示工程01.jpg](https://lilinchao.com/usr/uploads/2023/01/1919087492.jpg) #### 3、引入pom依赖 基本上nacos和sentinel都是一起配置 ```xml
4.0.0
com.lilinchao
SpringCloudAlibabaDemo
0.0.1-SNAPSHOT
com.lilinchao.springcloud
sentinel-service-demo01
8
8
UTF-8
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-discovery
com.alibaba.csp
sentinel-datasource-nacos
com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-devtools
runtime
true
cn.hutool
hutool-all
4.6.3
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
``` #### 4、配置application.yaml文件 ```yaml server: port: 8401 spring: application: name: sentinel-service-demo01 cloud: nacos: discovery: server-addr: localhost:8848 #Nacos服务注册中心地址 sentinel: transport: #配置Sentinel dashboard地址 dashboard: localhost:8050 #默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口 port: 8719 management: endpoints: web: exposure: include: '*' ``` #### 5、主启动类 ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryClient @SpringBootApplication public class SentinelServiceDemo01Application { public static void main(String[] args) { SpringApplication.run(SentinelServiceDemo01Application.class, args); } } ``` #### 6、业务类 + 创建FlowLimitController ```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class FlowLimitController { @GetMapping("/testA") public String testA() { return "------testA"; } @GetMapping("/testB") public String testB() { return "------testB"; } } ``` #### 7、测试 **(1)启动sentinel-dashboard-1.8.5.jar** ``` java -jar -Dserver.port=8050 sentinel-dashboard-1.8.5.jar ``` **(2)启动微服务sentinel-service-demo01,并查看** + 查看Nacos服务列表 ![02.Sentinel初始化演示工程02.jpg](https://lilinchao.com/usr/uploads/2023/01/1657973800.jpg) + 查看Sentinel 控制台 ![02.Sentinel初始化演示工程03.jpg](https://lilinchao.com/usr/uploads/2023/01/1100545462.jpg) 因为Sentinel采用懒加载机制,所以启动服务并没有立即看到服务信息 **(3)浏览器访问一下如下地址** ``` http://localhost:8401/testA ``` **(4)再次刷新Sentinel 控制台可以看到如下信息** ![02.Sentinel初始化演示工程04.jpg](https://lilinchao.com/usr/uploads/2023/01/1595681381.jpg)
标签:
SpringCloudAlibaba
,
Sentinel
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:
https://lilinchao.com/archives/2780.html
上一篇
01.Sentinel介绍
下一篇
03.Sentinel流控规则
取消回复
评论啦~
提交评论
栏目分类
随笔
2
Java
326
大数据
229
工具
31
其它
25
GO
47
标签云
字符串
Scala
RSA加解密
Spring
ClickHouse
数据结构和算法
Java编程思想
正则表达式
递归
FileBeat
Flume
gorm
Spark SQL
MyBatis-Plus
机器学习
链表
查找
Jquery
Flink
DataX
容器深入研究
设计模式
Java阻塞队列
MyBatis
Spark Streaming
Linux
Beego
Typora
HDFS
Kibana
友情链接
申请
范明明
庄严博客
Mx
陶小桃Blog
虫洞