Alibaba-cloud has never been used. In the process of using alibaba-Cloud-Sentinel module, we built a small experimental environment by ourselves. However, problems and solutions were summarized when using alibaba-Cloud-Sentinel module.

  1. Sentinel link flow control mode failed

    Solutions:

    1.1 Before and after Spring-Cloud-Alibaba V2.1.1.release, sentinel1.7.0, you need to turn off URL PATH aggregation in the following way. 1.1.1. The configuration file closed sentinel CommonFilter instantiate the spring. The cloud. Sentinel. Filter. The enabled = false 1.1.2. Add a configuration class, oneself build CommonFilter instance ` ` ` Java import com.alibaba.csp.sentinel.adapter.servlet.Com monFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration Public class FilterContextConfig {/** * @note Before and to spring-Cloud-Alibaba v2.1.1.RELEASE, sentinel1.7.0 and after, After spring-cloud-Alibaba v2.1.1.RELEASE, you can configure to disable URL PATH aggregation: Spring. Cloud. Sentinel. Web context - unity = false * manual injection sentinel filters, close the sentinel injection CommonFilter instance, Spring in the configuration file is modified. Cloud. Sentinel. Filter. The enabled = false * entry resource aggregation problem: https://github.com/alibaba/Sentinel/issues/1024 or https://github.com/alibaba/Sentinel/issues/1213 * entry resource aggregation problem solving: https://github.com/alibaba/Sentinel/pull/1111 */ @Bean public FilterRegistrationBean sentinelFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new CommonFilter()); registration.addUrlPatterns("/*"); / / entry resources close aggregation registration. AddInitParameter (CommonFilter WEB_CONTEXT_UNIFY, "false"); registration.setName("sentinelFilter"); registration.setOrder(1); return registration; }} ` ` `Copy the code

    1.2. After spring-Cloud-Alibaba v2.1.1.1. RELEASE, it can be shut down by configuration

    spring.cloud.sentinel.web-context-unify=false
    Copy the code

2. Sentinel 1.8 console integration Gateway cannot display flow control rules configured on NACOS

Solution: Add the startup parameter DCsp.sentinel.app. type=1. Generally, add dcsp.sentinel.app. type=1 when the gateway module is started.

3. The returned data is degraded by default

There are issues with the data returned by limiting and fusing – the microservice interaction is basically in JSON format, if you update the version of AlibabCloud with custom exception messages, there are incompatible issues

From v2.1.0 to v2.2.0, the dependencies in Sentinel were changed and the data returned was not backward compatible with custom degradation

Implement UrlBlockHandler and rewrite the Blocked method

@Component
public class XdclassUrlBlockHandler implements UrlBlockHandler {
    @Override
    public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
       // Degraded service processing}}Copy the code

[New] Implement BlockExceptionHandler and rewrite the Handle method

public class XdclassUrlBlockHandler implements BlockExceptionHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws Exception {
    // Degraded service processing}}Copy the code