本文主要是介绍springboot项目引入Sentinel熔断,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文是springboot项目+nacos进行引入,sentiel需自行按照部署
1.springboot包要是2.2.5或以上
<dubbo.version>2.7.7</dubbo.version><spring-boot.version>2.2.5.RELEASE</spring-boot.version><chainwork-boot.version>1.0.5-SNAPSHOT</chainwork-boot.version><nacos.version>0.2.7</nacos.version><spring-cloud-nacos-config.version>2.2.5.RELEASE</spring-cloud-nacos-config.version><spring-cloud.version>Hoxton.SR3</spring-cloud.version><spring-cloud-nacos-discovery.version>2.2.5.RELEASE</spring-cloud-nacos-discovery.version>
<!-- <arthas.version>3.4.3</arthas.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><nacos-client.version>1.4.1</nacos-client.version><redisson.version>3.13.6</redisson.version><spring-cloud-alibaba.version>2.2.5.RELEASE</spring-cloud-alibaba.version>
2.项目后端需依赖包
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>${spring-cloud-alibaba.version}</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><version>${spring-cloud-alibaba.version}</version></dependency><!-- Sentinel数据源之 Nacos --><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.0</version></dependency><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-web-servlet</artifactId><version>1.8.0</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.6</version></dependency><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId></dependency><dependency><groupId>javax.validation</groupId><artifactId>validation-api</artifactId><version>2.0.1.Final</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>5.0.1.Final</version></dependency>
3.项目前端需依赖包
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>${spring-cloud-alibaba.version}</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><version>${spring-cloud-alibaba.version}</version></dependency><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.0</version></dependency><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-web-servlet</artifactId><version>1.8.0</version></dependency><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.6</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>RELEASE</version><scope>compile</scope></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency>
<dependency><groupId>javax.validation</groupId><artifactId>validation-api</artifactId><version>2.0.1.Final</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>5.0.1.Final</version></dependency>
4.后端 bootstrap.yml需配置
#server:
# port: 8888
spring:# application:# name: test-servermain:allow-bean-definition-overriding: truecloud:sentinel:datasource:# 流控规则,名字任意ds-flow:nacos:## nacos的地址server-addr: 11.11.11.11:8848## 配置IDdataId: ${spring.application.name}-flow-rules## 配置存储的格式data-type: json## 配置分组,默认是DEFAULT_GROUPgroupId: SENTINEL_GROUPrule-type: flow## 配置降级规则,名字任意ds-degrade:nacos:## nacos的地址server-addr: 11.11.11.11:8848## 配置IDdataId: ${spring.application.name}-degrade-rules## 配置分组,默认是DEFAULT_GROUPgroupId: SENTINEL_GROUP## 配置存储的格式data-type: json## rule-type设置对应得规则类型,总共七大类型,在com.alibaba.cloud.sentinel.datasource.RuleType这个枚举类中有体现rule-type: degrade## 配置系统规则,名字任意ds-system:nacos:## nacos的地址server-addr: 11.11.11.11:8848##
这篇关于springboot项目引入Sentinel熔断的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!