首页 > 技术文章 > alibaba-sentinel-1.8变化

cu-later 2020-12-15 09:16 原文

  1. maven最新坐标
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
    </dependencies>
  1. 业务降级处理接口变化UrlBlockHandler ->BlockExceptionHandler
  2. 配置变化 WebCallbackManager被删除 只需要创建 BlockExceptionHandler 接口实现类即可实现自动配置
      @Configuration
public class SentinelConfig {

	@Bean
	public BlockExceptionHandler sentinelBlockExceptionHandler() {
		return (request, response, e) -> {
			// 429 Too Many Requests
			response.setStatus(429);

			PrintWriter out = response.getWriter();
			out.print("Oops, blocked by Sentinel: " + e.getClass().getSimpleName());
			out.flush();
			out.close();
		};
	}

}
  1. 参考官方demo

推荐阅读