「升级指南」Spring Cloud Alibaba v2.2.0 升级问题整理
2020/2/25 17:15:30
本文主要是介绍「升级指南」Spring Cloud Alibaba v2.2.0 升级问题整理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
前言
上周(2020.02.12)我们写了一篇关于《Spring Cloud Alibaba V2.2.0 发布》 相关的特性,v2.2.0
是基于 Spring Cloud Hoxton
的版本。下面总结一下由 Spring Cloud Alibaba v2.1.0
升级至 v2.2.0
遇到的问题。
主要问题涉及 sentinel
的问题。
破坏性 ,不向下兼容
Spring Cloud Alibaba Sentinel
不再依赖 sentinel-web-servlet
实现,而是依赖 sentinel-spring-webmvc-dapter
, 基于 Spring 的 Interceptor
拦截资源,而不再是 CommonFilter
。
降级策略修改
实现接口发现变化
// 之前版本 public class PigxUrlBlockHandler implements UrlBlockHandler { @Override public void blocked(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException { // 降级业务处理 } } // v2.2.0 public class PigxUrlBlockHandler implements BlockExceptionHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception { // 降级业务处理 } }复制代码
请求解析器
实现接口的包发生变化
//旧版本 import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; // v2.2.0 import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser; // 请求解析器实现 public class PigxHeaderRequestOriginParser implements RequestOriginParser { private static final String ALLOW = "Allow"; @Override public String parseOrigin(HttpServletRequest request) { return request.getHeader(ALLOW); } }复制代码
默认情况下只拦截 /*
请求
上文提到V2.2.0
是基于 Interceptor
实现,默认拦截规则为 /*
, 也就是只有 请求URI 为 / ,/a 的请求可以被sentinel处理,dashboard
也只会显示被拦截的资源,需要配置一下拦截规则。 此问题我们已提交 pull request
修复Modify the sentinelInterceptor default interception rule and backward
spring: cloud: sentinel: filter: url-patterns: /**复制代码
涉及源码: SentinelWebAutoConfiguration.addInterceptors()
默认情况: spring boot admin
显示部分服务为 down
,控台只显示部分服务
访问服务 IP:PORT/actuator/health
显示sentinel 状态为 down
,默认情况下 sentinel 是懒加载的,在启动时不会立即给 sentinel-server
发送心跳,导致SentinelHealthIndicator
将状态判为 false
,进而导致 Spring Boot Admin
读取到 actuator
信息为 down
可以设置饥饿加载,启动加载时就会加载,并发送心跳
spring: cloud: sentinel: eager: true复制代码
源码可以参考: SentinelAutoConfiguration.init()
, 利用SPI
加载对应的 业务
总结
Spring Cloud Alibaba Sentinel
模块源码,处理逻辑相对简单明了建议通读。核心是初始化 sentinel
的dapter
,并且注入了 默认的降级等实现。
『★★★★★』 基于Spring Boot 2.2、 Spring Cloud Hoxton & Alibaba、 OAuth2 的RBAC 权限管理系统
这篇关于「升级指南」Spring Cloud Alibaba v2.2.0 升级问题整理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南
- 2024-09-30Dnd-Kit学习:新手快速入门指南