springboot+dubbo+nacos+sentinel搭建

上一篇详细讲了springboot+dubbo+nacos,在篇是在它的基础上加上sentinel

注意,没有依赖springcloud的包

一、下载安装sentinel-dashboard 即是sentinel的控制台

https://github.com/alibaba/Sentinel/releases

注意:启动 Sentinel dashboard控制台需要 JDK 版本为 1.8 及以上版本。

启动命令

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.1.jar

界面访问地址

http://localhost:8080

默认用户名和密码都是 sentinel

二、客户端接入控制台

客户端需要引入 Transport 模块来与 Sentinel 控制台进行通信。

springboot+dubbo+nacos项目中集成sentinel。

这是在上一篇的基础之上做的修改,这里是加在business、storage、order、account项目里面的。

pom.xml

<!--
   dubbo 版本 Apache Dubbo 2.7.x 及以上版本
  sentinel-apache-dubbo-adapter
   对于Dubbo 2.6.x 及以下版本 sentinel-dubbo-adapter
 -->
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-apache-dubbo-adapter</artifactId>
    <version>1.8.1</version>
</dependency>
 
<!--使用sentinel dashboard导入-->
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-transport-simple-http</artifactId>
    <version>1.8.1</version>
</dependency>

注意

与dubbo 版本整合时:

      dubbo 版本 Apache Dubbo 2.7.x 及以上版本 sentinel-apache-dubbo-adapter

       对于Dubbo 2.6.x 及以下版本 sentinel-dubbo-adapter

     如果dubbo版本使用2.7.x 使用了sentinel-dubbo-adapter jar服务调用时会出问题错误如下:

               java.lang.NoSuchMethodError: com.alibaba.dubbo.rpc.RpcContext.setAttachment

客户端启动的JVM参数加入

-Dcsp.sentinel.dashboard.server=localhost:8080 -Dcsp.sentinel.api.port=8719

比如

business项目的启动参数

-Dcsp.sentinel.dashboard.server=localhost:8080 -Dcsp.sentinel.api.port=8719 -Dproject.name=app-business

storage项目里面的启动参数

-Dcsp.sentinel.dashboard.server=localhost:8080 -Dcsp.sentinel.api.port=8719 -Dproject.name=app-storage

order项目里面的启动参数

-Dcsp.sentinel.dashboard.server=localhost:8080 -Dcsp.sentinel.api.port=8719 -Dproject.name=app-order

account项目里面的启动参数

-Dcsp.sentinel.dashboard.server=localhost:8080 -Dcsp.sentinel.api.port=8719 -Dproject.name=app-account

然后直接启动,然后触发一次RPC调用,打开sentinel的控制界面可以看到,这些项目已经在给sentinel上报数据了

新建流控

 这是在方法级别限流,在business端,限制business调用storage的流量


版权声明:本文为jy02268879原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。