• HZero服务启用Sentinel监控功能

    开启后,Sentinel会自动记录请求次数、成功率等数据,帮助排查问题。

    网关服务hzero-gateway

    	<!-- 当前HZero所依赖Spring Cloud版本为2.0.6,对应Spring Cloud Alibaba版本为2.0.x -->
    	<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
    

    配置项说明

    # 控制台上不展示url资源
    spring.cloud.sentinel.filter.enabled=false
    

    其他服务

    	<!-- 当前HZero所依赖Spring Cloud版本为2.0.6,对应Spring Cloud Alibaba版本为2.0.x -->
    	<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
    

    配置项说明

    feign.sentinel.enabled=true
    
    @Bean
    @SentinelRestTemplate(blockHandler = "handleException", blockHandlerClass = ExceptionUtil.class)
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
    
    public static class ExceptionUtil {
        public static ClientHttpResponse handleException(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException exception) {
            ...
        }
    }