"Upgrade Guide" Spring Cloud Alibaba v2.2.0 upgrade issues finishing

Foreword

Last week (2020.02.12) we wrote an article on "Spring Cloud Alibaba V2.2.0 release" characteristics related, v2.2.0is based on the Spring Cloud Hoxtonversion. The following summarize the Spring Cloud Alibaba v2.1.0upgrade to v2.2.0the problems encountered.

The main issues involved sentinelin the issue.

Destructive, not backward compatible

Spring Cloud Alibaba SentinelNo longer dependent on sentinel-web-servletimplementation, but rather rely on sentinel-spring-webmvc-dapterSpring-based Interceptorinterceptors resources, instead CommonFilter.

Downgrade policy modification

Found that implements the interface changes

// 之前版本 
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 {
    // 降级业务处理
    }
}复制代码

Request parser

The package implements the interface changes

//旧版本
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);
  }
}复制代码

By default, only interception /*request

Mentioned above V2.2.0is based on the Interceptorrealization, the default rule for the interception /*, which is the only request URI is /, / a sentinel request can be processed, dashboardit will only display the intercepted resource, need to configure blocking rules. This issue has been submitted to us pull requestfix Modify the sentinelInterceptor default interception rule and backward

spring:
  cloud:
    sentinel:
      filter:
        url-patterns: /**复制代码

Involved Source: SentinelWebAutoConfiguration.addInterceptors()

Default: spring boot admindisplayed as part of the service down, the console will display only part of the service

Access Services IP:PORT/actuator/healthdisplay sentinel state down, by default sentinel is lazy loaded at startup will not immediately to sentinel-serversend heartbeat, leading to SentinelHealthIndicatora state ruled false, leading to Spring Boot Adminread actuatorinformationdown

Hunger can be set to load, it will be loaded at startup to load, and send the heartbeat

spring:
  cloud:
    sentinel:
      eager: true复制代码

Source can refer: SentinelAutoConfiguration.init()by SPIloading a corresponding service

to sum up

Spring Cloud Alibaba SentinelSource module, the processing logic read relatively straightforward recommendations. The core is the initialization sentinelof dapter, and injected the default demotion or the like.

"★★★★★" Based on Spring Boot 2.2, Spring Cloud Hoxton & Alibaba, OAuth2 of RBAC rights management systemimage

Guess you like

Origin juejin.im/post/5e5488986fb9a07cb24a9d46