当前位置: 首页 > news >正文

正规的环保行业网站开发关键词搜索量怎么查

正规的环保行业网站开发,关键词搜索量怎么查,网页游戏排行榜前十推荐,网上如何建平台网站限流规则配置 每次服务重启后 之前配置的限流规则就会被清空因为是内存态的规则对象#xff0c;所以就要用到Sentinel一个特性ReadableDataSource 获取文件、数据库或者配置中心是限流规则 依赖#xff1a;spring-cloud-alibaba-sentinel-datasource 通过文件读取限流规则…限流规则配置 每次服务重启后 之前配置的限流规则就会被清空因为是内存态的规则对象所以就要用到Sentinel一个特性ReadableDataSource 获取文件、数据库或者配置中心是限流规则 依赖spring-cloud-alibaba-sentinel-datasource 通过文件读取限流规则 spring.cloud.sentinel.datasource.ds1.file.fileclasspath:flowrule.json spring.cloud.sentinel.datasource.ds1.file.data-typejson spring.cloud.sentinel.datasource.ds1.file.rule-typeflow在resources新建一个文件 比如flowrule.json 添加限流规则 [{resource: resource,controlBehavior: 0,count: 1,grade: 1,limitApp: default,strategy: 0} ]RestController public class TestController {GetMapping(/test1)SentinelResource(value resource)public String sayHello(String name){if(namenull || name.trim().length()1)throw new IllegalArgumentException(参数为空!);return Hello name!;} }一条限流规则主要有 resource资源名即限流规则的作用对象 count限流阈值 grade限流阈值类型0表示线程,1表示QPS limitApp流控针对的调用来源若为 default 则不区分调用来源 strategy调用关系限流策略,0表示直接,1表示关联,2表示链路 controlBehavior流量控制效果0表示快速失败,1表示Warm Up,2表示排队等待 隔离降级 限流是一种预防措施虽然限流可以尽量避免因高并发而引起的服务故障但服务还会因为其它原因而故障。而要将这些故障控制在一定范围避免雪崩就要靠线程隔离舱壁模式和熔断降级手段了。 线程隔离就是调用者在调用服务提供者时给每个调用的请求分配独立线程池出现故障时最多消耗这个线程池内资源避免把调用者的所有资源耗尽 熔断降级是在调用方这边加入断路器统计对服务提供者的调用如果调用的失败比例过高则熔断该业务不允许访问该服务的提供者了。 不管是线程隔离还是熔断降级都是对客户端调用方的保护。需要在调用方发起远程调用时做线程隔离、或者服务熔断。 RestTemplate整合Sentinel Spring Cloud Alibaba Sentinel 支持对 RestTemplate 的服务调用使用 Sentinel 进行保护在构造RestTemplate bean的时候需要加上 SentinelRestTemplate 注解。 SentinelRestTemplate 注解的属性支持限流(blockHandler, blockHandlerClass)和降级(fallback, fallbackClass)的处理。 SentinelRestTemplate用于sentinel 集成 RestTemplate。可以添加在 RestTemplate上全局的限流容错处理优先级低于局部限流容错注解。例如 SentinelRestTemplate(blockHandler handleException, blockHandlerClass ExceptionUtil.class, fallback fallback,fallbackClass ExceptionUtil.class) blockHandler限流策略 方法名方法必须是静态的 blockHandlerClass 限流方法类 fallback 熔断降级策略方法名方法必须是静态的 fallbackClass 熔断降级类 Bean LoadBalance SentinelRestTemplate public RestTemplate restTemplate(){return new RestTemplate(); }对应实现static修饰参数类型不能出错 public class ExceptionUtil {// 服务流量控制处理public static ClientHttpResponse handleException(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException exception){exception.printStackTrace();return new SentinelClientHttpResponse( JSON.toJSONString(new Product(1, 服务流量控制处理-托底数据)));}// 服务熔断降级处理public static ClientHttpResponse fallback(HttpRequest request,byte[] body, ClientHttpRequestExecution execution, BlockException exception) {exception.printStackTrace();return new SentinelClientHttpResponse( JSON.toJSONString(new Product(1, 服务熔断降级处理-托底数据)));} }FeignClient整合Sentinel SpringCloud中微服务调用都是通过Feign来实现的因此做客户端保护必须整合Feign和Sentinel。 在启动类上面加个注解 EnableFeignClients 修改OrderService的application.yml文件开启Feign的Sentinel功能 feign.sentinel.enabledtrue开启feign对sentinel的支持 方法1定义对应FeignClient接口的实现类提供对应的处理 Component public class UserClientImpl implements UserClient {Overridepublic JsonResult getAllUsers() {return JsonResult.failure(103,加载失败...);} }然后在FeignClient上添加注解说明 FeignClient(valueuser-provider,fallback UserClientImpl.class) public interface UserClient {GetMapping(/users)public JsonResult getAllUsers(); }方法2自定义工厂 [推荐使用] Component public class MyFeignFactory implements FallbackFactoryUserClient {Overridepublic UserClient create(Throwable cause) {return new UserClient() {Overridepublic JsonResult getAllUsers() {return JsonResult.failure(1031,加载失败...);}};} }在配置类中添加配置 Bean public MyFeignFactory myClientFallbackFactory(){return new MyFeignFactory(); }在FeignClient接口上添加配置使用MyFeignFactory FeignClient(valueuser-provider,fallbackFactory MyFeignFactory.class) public interface UserClient {GetMapping(/users)public JsonResult getAllUsers(); }失败降级逻辑 业务失败后不能直接报错而应该返回用户一个友好提示或者默认结果这个就是失败降级逻辑。可以给FeignClient编写失败后的降级逻辑。 方式一FallbackClass无法对远程调用的异常做处理 方式二FallbackFactory可以对远程调用的异常做处理 定义类实现FallbackFactory Slf4j public class UserClientFallbackFactory implements FallbackFactoryUserClient {Overridepublic UserClient create(Throwable throwable) {return new UserClient() {Overridepublic User findById(Long id) {log.error(查询用户异常, throwable);return new User();}};} }项目中的DefaultFeignConfiguration类中将UserClientFallbackFactory注册为一个Bean Bean public UserClientFallbackFactory userClientFallbackFactory(){return new UserClientFallbackFactory(); }项目中的UserClient接口中使用UserClientFallbackFactory FeignClient(value userservice, fallbackFactory UserClientFallbackFactory.class) public interface UserClient {GetMapping(/user/{id})User findById(PathVariable(id) Long id); }在需要被保护的方法上使用SentinelResource注解进行熔断配置。与Hystrix不同的是Sentinel对抛出异常和熔断降级做了更加细致的区分通过 blockHandler 指定熔断降级方法通过 fallback 指定 触发异常执行的降级方法 GetMapping(/buy/{id}) SentinelResource(valueorder,blockHandler orderblockHandler,fallbackorderfallback) public Product order(PathVariable Long id) {return restTemplate.getForObject(http://shop- service/product/product/1, Product.class); } //降级方法 public Product orderblockHandler(Long id) {Product product new Product();product.setId(-1l);product.setProductName(触发熔断降级方法);return product; } //降级方法 public Product orderfallback(Long id) {Product product new Product();product.setId(-1l);product.setProductName(触发抛出异常方法);return product; }隔离降级总结 Sentinel支持的雪崩解决方案线程隔离的仓壁模式、降级熔断
http://www.pierceye.com/news/440230/

相关文章:

  • 深圳做网站好的公司wordpress建菜单
  • 网站编辑需要的技能做网站需要什么域名
  • 营销型网站建设目的和意义网站托管方案
  • 网站感谢页面企业标志图片大全
  • 响应式网站建设必推全网天下邵阳竞价网站建设设计
  • 大连网站如何制作辽阳公司做网站
  • 百度站长怎么验证网站jekyll做公司网站
  • 电子商务公司建设网站方案设计网站建设开发背景
  • 同一产品做多个网站山西省住房和城乡建设厅官网
  • 网站建设的流程是什么意思微信小程序的代码
  • 广州网站整站优化html项目案例实战
  • 宁波网站推广方式seo优化按天扣费
  • 紫金优化网站制作python编程100例
  • 原阳网站建设哪家好域名网址
  • 西安学校网站建设wordpress手机端模板下载
  • 泉州网站建设工作室网站上的产品板块
  • 平顶山网站网站建设网页设计与制作教程 刘瑞信 pdf
  • 网站开发深天津设计公司排行榜
  • 做tcf法语听力题的网站公司网页简介
  • 十堰做网站最专业的公司深圳企业网查询
  • 购物网站大全排名调查drupal与wordpress哪个容易
  • 网站建设彳金手指排名网站开发完没人运营
  • 网站建设是设开发公司质量管理流程
  • 金沙网站怎么做代理wordpress tag=
  • 做网站必须花钱吗建筑人才网证书查询
  • 0基础网站建设模板工商注册官方网站
  • 河南网站设计公司价格网站在建设中是什么意思
  • 网站建设公司的成本有哪些方面四川省城乡建设网查询
  • 和什么人合作做游戏视频网站做推送网站
  • 做竞价网站访问突然变少施工企业负责人带班检查计划