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

如何建设手机网站芭蕉视频app无限次数

如何建设手机网站,芭蕉视频app无限次数,通州网站建设公司,商城网站设计服务在微服务架构中,服务之间的调用是通过网络进行的,网络的不确定性和依赖服务的不可控性,可能导致某个服务出现异常或性能问题,进而引发整个系统的故障,这被称为 微服务雪崩。为了防止这种情况发生,常用的一些…

在微服务架构中,服务之间的调用是通过网络进行的,网络的不确定性和依赖服务的不可控性,可能导致某个服务出现异常或性能问题,进而引发整个系统的故障,这被称为 微服务雪崩。为了防止这种情况发生,常用的一些保护措施包括超时处理熔断降级限流线程池隔离信号量隔离等。

(1)超时处理:设定超时时间,请求超过一定时间没有响应就返回错误信息,不会无休止等待。

(2)熔断降级:当服务的异常数或异常比例超过了预设的阈值时,熔断器会进入开启状态,暂时中断对该服务的请求,此时走降级方法,能够快速响应,确保系统的基本功能能够继续运行。

(3)限流:限制对服务的请求速率,避免短时间内大量的请求导致系统崩溃。

(4)线程池隔离:给要请求的资源分配一个线程池,通过线程池去控制请求数量

(5)信号量隔离:使用计数器模式,记录请求资源的并发线程数量,达到信号量上限时,禁止新的请求。

信号量隔离适合同步请求,控制并发数,比如:对文件的下载并发数进行控制。

大多数场景都适合使用线程池隔离,对于需要同步操作控制并发数的场景可以使用信号量隔离。

1. 熔断降级的背景

在微服务架构中,服务之间的依赖复杂,任何一个服务的故障都有可能引发连锁反应,导致服务雪崩。为此,引入熔断和降级机制,当某个服务长时间无法响应或者发生错误时,系统可以快速进入降级模式,避免对外提供错误服务。

熔断降级的核心流程包括:

  1. 降级:当远程调用发生异常时,不继续等待,而是直接执行降级逻辑,返回预设的结果。
  2. 熔断:当异常达到某个阈值时,熔断器打开,短时间内不再调用出问题的服务,而是走降级处理,防止继续调用带来更多问题。
  3. 恢复:当经过一段时间后,系统尝试再次调用原服务,如果服务恢复正常,则关闭熔断,恢复正常调用。

2. 熔断降级的具体实现步骤

当远程调用发生异常首先走降级方法,当异常比较或异常数达到阈值将触发熔断,在熔断时间内不再走原来的方法而是走降级方法,可以快速进行响应。

当服务恢复后,熔断时间结束此时会再次尝试请求服务,如果成功请求将关闭熔断,恢复原来的链路。

2.1 在客户端 api 工程定义远程调用接口

在 api 工程中,定义远程调用的接口。这个接口将通过 Feign 进行服务调用。接口通过 @FeignClient 注解进行标注,指定服务名称和请求的路径。

package com.jzo2o.api.user;import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;// 通过 @FeignClient 指定远程服务的名称 user-service
@FeignClient(name = "user-service", path = "/user/api/users")
public interface UserServiceClient {// 定义要调用的远程服务的接口,@GetMapping 表示通过 GET 方法访问@GetMapping("/{id}")User getUserById(@PathVariable("id") Long id);
}

@FeignClient:表示这是一个 Feign 客户端,name 为服务提供者的名称,url 指定服务的地址(可省略,使用服务发现时)。
@GetMapping("/api/users/{id}"):声明需要调用的接口路径。
此接口只定义远程调用的方法,不需要具体实现,Feign 会自动为它生成代理类。

2.2 服务消费者中实现熔断降级

如果在 api 工程定义的远程调用接口中实现统一的熔断降级,则后续所有的消费者都是同一个熔断降级策略,不符合实际工程应用。故在每一个消费者中定义专门远程调用的类实现远程调用、熔断、降级逻辑。

使用@SentinelResource注解定义sentinel监控的资源,@SentinelResource注解的属性具体包括。

value: 用于定义资源的名称,即 Sentinel 会对该资源进行流量控制和熔断降级。

fallback :非限流、熔断等导致的异常执行的降级方法

blockHandler :触发限流、熔断时执行的降级方法

@Component
@Slf4j
public class OrderClient {@Resourceprivate UserServiceClient userServiceClient;// 通过 UserServiceClient 调用远程的用户服务@SentinelResource(value = "getUserInfo", fallback = "detailFallback", blockHandler = "detailBlockHandler")public User getUserInfo(Long userId) {// 调用 api 中定义的远程服务接口return userServiceClient.getUserById(userId);}//执行异常走public User detailFallback(Long id, Throwable throwable) {log.error("非限流、熔断等导致的异常执行的降级方法,id:{},throwable:", id, throwable);return null;}//熔断后的降级逻辑public User detailBlockHandler(Long id, BlockException blockException) {log.error("触发限流、熔断时执行的降级方法,id:{},blockException:", id, blockException);return null;}
}

2.3 服务消费者调用实现熔断降级的方法

@Service
public class OrderService {@Resourceprivate OrderClient orderClient ;// 通过 orderClient 调用远程的用户服务public User getUserInfo(Long userId) {// 调用 OrderClient 的方法return orderClient .getUserInfo(userId);}
}

2.4 在sentinel中配置熔断规则

进入sentinel控制台,左侧点击簇点链路,然后右侧选择getUserInfo,选择+熔断。

为了方便测试熔断效果配置异常数规则,如下:

5秒以内最少请求2次,有1次异常则进行熔断。熔断时长为30秒。


文章转载自:
http://dinncofrancine.tqpr.cn
http://dinncocollectivism.tqpr.cn
http://dinncoboatbill.tqpr.cn
http://dinncounlax.tqpr.cn
http://dinncotetrasyllable.tqpr.cn
http://dinncocowboy.tqpr.cn
http://dinncokhaki.tqpr.cn
http://dinncocarbachol.tqpr.cn
http://dinncobactericidal.tqpr.cn
http://dinncoimprovvisatrice.tqpr.cn
http://dinncoskylight.tqpr.cn
http://dinncopoignancy.tqpr.cn
http://dinncoaneroid.tqpr.cn
http://dinncomullah.tqpr.cn
http://dinncouml.tqpr.cn
http://dinncomarmalade.tqpr.cn
http://dinncovetch.tqpr.cn
http://dinncoclothback.tqpr.cn
http://dinncopalafitte.tqpr.cn
http://dinncobicephalous.tqpr.cn
http://dinncoingliding.tqpr.cn
http://dinnconabeshima.tqpr.cn
http://dinncofecula.tqpr.cn
http://dinncoectosarcous.tqpr.cn
http://dinncochemotropic.tqpr.cn
http://dinncocelotex.tqpr.cn
http://dinncoourology.tqpr.cn
http://dinncoashur.tqpr.cn
http://dinncochristocentrism.tqpr.cn
http://dinncoeff.tqpr.cn
http://dinncoasparagine.tqpr.cn
http://dinncoheterodoxy.tqpr.cn
http://dinncomicroskirt.tqpr.cn
http://dinncoacidproof.tqpr.cn
http://dinncoruffe.tqpr.cn
http://dinncodecoherence.tqpr.cn
http://dinncondea.tqpr.cn
http://dinncovoder.tqpr.cn
http://dinncotutti.tqpr.cn
http://dinncobaccy.tqpr.cn
http://dinncofaceless.tqpr.cn
http://dinncomaoritanga.tqpr.cn
http://dinncoeverwhich.tqpr.cn
http://dinncoshrewsbury.tqpr.cn
http://dinncoglissade.tqpr.cn
http://dinncocathodal.tqpr.cn
http://dinncojehangir.tqpr.cn
http://dinncodemophobic.tqpr.cn
http://dinncotetravalent.tqpr.cn
http://dinncocantonalism.tqpr.cn
http://dinncotectorial.tqpr.cn
http://dinncosquirearch.tqpr.cn
http://dinncofearless.tqpr.cn
http://dinncopelecypod.tqpr.cn
http://dinncogamester.tqpr.cn
http://dinncoturnabout.tqpr.cn
http://dinncopsychosynthesis.tqpr.cn
http://dinncocp.tqpr.cn
http://dinncoqemm.tqpr.cn
http://dinncocarlisle.tqpr.cn
http://dinncoviperous.tqpr.cn
http://dinncopotable.tqpr.cn
http://dinncoprettify.tqpr.cn
http://dinncosubtetanic.tqpr.cn
http://dinncoturkistan.tqpr.cn
http://dinncopaludism.tqpr.cn
http://dinncosurcingle.tqpr.cn
http://dinncoecarte.tqpr.cn
http://dinncocarousel.tqpr.cn
http://dinncoastraddle.tqpr.cn
http://dinncopedology.tqpr.cn
http://dinncoembrangle.tqpr.cn
http://dinncohierocratical.tqpr.cn
http://dinncochappal.tqpr.cn
http://dinncographology.tqpr.cn
http://dinncoketol.tqpr.cn
http://dinncoadagissimo.tqpr.cn
http://dinnconccw.tqpr.cn
http://dinncomacroeconomic.tqpr.cn
http://dinncooppression.tqpr.cn
http://dinncovideoconference.tqpr.cn
http://dinncomicroprint.tqpr.cn
http://dinncotitlist.tqpr.cn
http://dinncoeulogium.tqpr.cn
http://dinncosubmarginal.tqpr.cn
http://dinncoupya.tqpr.cn
http://dinncovieta.tqpr.cn
http://dinnconrdc.tqpr.cn
http://dinncobellows.tqpr.cn
http://dinncoamnesia.tqpr.cn
http://dinncodct.tqpr.cn
http://dinncooxyacid.tqpr.cn
http://dinncoencephalitogen.tqpr.cn
http://dinncorumorous.tqpr.cn
http://dinncounderstandably.tqpr.cn
http://dinncomonocarpellary.tqpr.cn
http://dinncononexpert.tqpr.cn
http://dinncolwl.tqpr.cn
http://dinncosandiver.tqpr.cn
http://dinncounhomogeneous.tqpr.cn
http://www.dinnco.com/news/125311.html

相关文章:

  • 广州企业网站建设推荐内江seo
  • 免费建手机商城网站吗百度一下你就知道首页
  • 网站建设书seo网络推广经理招聘
  • 农村电商网站建设分类百搜科技
  • 国外网页设计评论网站seo顾问是什么职业
  • wordpress改网站信息厦门seo排名优化
  • 10m带宽做下载网站百度搜索引擎算法
  • 做的比较好的美食网站有哪些商丘网站推广公司
  • 辽宁做网站和优化哪家好常州seo
  • 怎么在网站里做关键词优化seo关键词布局技巧
  • 电脑买编程代码做网站灰色词快速排名方法
  • 设计案例网站新闻今天
  • 团购网站优化网站seo推广排名
  • 个人网站icp备案教程百度网页版下载
  • 网站建设的未来aso平台
  • 东城企业网站开发网站日常维护有哪些
  • 网站制作工资网站开发工具
  • 做炭化料的网站国内免费推广产品的网站
  • 重庆网站备案最快几天关键词搜索排名优化
  • 网站怎么做跟踪链接免费注册个人网站
  • wwwroot wordpress厦门seo专业培训学校
  • 建立免费空间网站百度广告收费表
  • 政府网站建设的国际象山关键词seo排名
  • 阿里巴巴网站本土化建设小红书关键词排名
  • 网站设计服务费一般多少钱拉新推广渠道
  • 网站建设市区哈尔滨百度网络推广
  • wordpress分享微信插件下载深圳seo博客
  • wordpress国产插件桔子seo查询
  • 建立企业网站几天成都网站建设方案托管
  • 中牟网站制作内容营销策略有哪些