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

360广告联盟怎么做网站百度百科优化

360广告联盟怎么做网站,百度百科优化,php做网站访问记录,松江网站开发1.前言 上篇文章讲了Resilience4J实现熔断功能&#xff0c;文章详见&#xff1a;Spring Boot集成Resilience4J实现断路器功能 | Harries Blog™&#xff0c;本篇文章主要讲述基于Resilience4J实现限流/重试/隔离。 2.代码工程 pom.xml <dependency><groupId>io…

1.前言

上篇文章讲了Resilience4J实现熔断功能,文章详见:Spring Boot集成Resilience4J实现断路器功能 | Harries Blog™,本篇文章主要讲述基于Resilience4J实现限流/重试/隔离。

2.代码工程

pom.xml

<dependency><groupId>io.github.resilience4j</groupId><artifactId>resilience4j-spring-boot3</artifactId><version>2.0.2</version>
</dependency>
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

限流

@RequestMapping("/hello")
@RateLimiter(name="ratelimitApi",fallbackMethod = "fallback")
public ResponseEntity<String> showHelloWorld(){return new ResponseEntity<>("success",HttpStatus.OK);}
public ResponseEntity fallback(Throwable e){log.error("fallback exception , {}",e.getMessage());return new ResponseEntity<>("your request is too fast,please low down", HttpStatus.OK);
}

重试

@RequestMapping("/retry")
@Retry(name = "backendA")//use backendA ,if throw IOException ,it will be retried 3 times。
public ResponseEntity<String> retry(String name){if(name.equals("test")){i++;log.info("retry time:{}",i);throw  new HttpServerErrorException(HttpStatusCode.valueOf(101));}return new ResponseEntity<>("retry",HttpStatus.OK);
}

隔离

@RequestMapping("/bulkhead")
@Bulkhead(name = "backendA")
public ResponseEntity<String> bulkhead(){return new ResponseEntity<>("bulkhead",HttpStatus.OK);
}

配置文件

spring:application.name: resilience4j-demojackson.serialization.indent_output: truemanagement:endpoints.web.exposure.include:- '*'endpoint.health.show-details: alwayshealth.circuitbreakers.enabled: trueresilience4j:circuitbreaker:configs:default:registerHealthIndicator: trueslidingWindowSize: 10minimumNumberOfCalls: 5permittedNumberOfCallsInHalfOpenState: 3automaticTransitionFromOpenToHalfOpenEnabled: truewaitDurationInOpenState: 5sfailureRateThreshold: 50eventConsumerBufferSize: 10ratelimiter: instances:ratelimitApi:limit-for-period: 5 limit-refresh-period: 1s timeout-duration: 100ms retry:instances:backendA:maxAttempts: 3waitDuration: 10senableExponentialBackoff: trueexponentialBackoffMultiplier: 2retryExceptions:- org.springframework.web.client.HttpServerErrorException- java.io.IOExceptionbulkhead:instances:backendA:maxConcurrentCalls: 10

以上只是一些关键代码,所有代码请参见下面代码仓库

代码仓库

  • GitHub - Harries/springboot-demo: a simple springboot demo with some components for example: redis,solr,rockmq and so on.(Resilience4J)

3.测试

1.启动Spring Boot应用程序

测试限流

public class ThreadTest {public static void main(String[] args) {for(int i=0;i<6;i++){new Thread(()->{System.out.println(new RestTemplate().getForObject("http://localhost:8080/hello",String.class));}).start();}}
}

运行main方法

io.github.resilience4j.bulkhead.BulkheadFullException: Bulkhead 'backendA' is full and does not permit further callsat io.github.resilience4j.bulkhead.BulkheadFullException.createBulkheadFullException(BulkheadFullException.java:49) ~[resilience4j-bulkhead-2.0.2.jar:2.0.2]at io.github.resilience4j.bulkhead.internal.SemaphoreBulkhead.acquirePermission(SemaphoreBulkhead.java:164) ~[resilience4j-bulkhead-2.0.2.jar:2.0.2]at io.github.resilience4j.bulkhead.Bulkhead.lambda$decorateCheckedSupplier$0(Bulkhead.java:68) ~[resilience4j-bulkhead-2.0.2.jar:2.0.2]at io.github.resilience4j.bulkhead.Bulkhead.executeCheckedSupplier(Bulkhead.java:471) ~[resilience4j-bulkhead-2.0.2.jar:2.0.2]at io.github.resilience4j.spring6.bulkhead.configure.BulkheadAspect.handleJoinPoint(BulkheadAspect.java:194) ~[resilience4j-spring6-2.0.2.jar:2.0.2]at io.github.resilience4j.spring6.bulkhead.configure.BulkheadAspect.proceed(BulkheadAspect.java:147) ~[resilience4j-spring6-2.0.2.jar:2.0.2]at io.github.resilience4j.spring6.bulkhead.configure.BulkheadAspect.lambda$bulkheadAroundAdvice$1(BulkheadAspect.java:120) ~[resilience4j-spring6-2.0.2.jar:2.0.2]at io.github.resilience4j.spring6.fallback.FallbackExecutor.execute(FallbackExecutor.java:37) ~[resilience4j-spring6-2.0.2.jar:2.0.2]at io.github.resilience4j.spring6.bulkhead.configure.BulkheadAspect.bulkheadAroundAdvice(BulkheadAspect.java:121) ~[resilience4j-spring6-2.0.2.jar:2.0.2]at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637) ~[spring-aop-6.1.2.jar:6.1.2]

测试重试

访问http://127.0.0.1:8080/retry?name=test

2024-08-03T23:16:32.092+08:00 INFO 5097 --- [resilience4j-demo] [nio-8080-exec-9] c.e.r.controller.HelloWorldController : retry time:1
2024-08-03T23:16:42.120+08:00 INFO 5097 --- [resilience4j-demo] [nio-8080-exec-9] c.e.r.controller.HelloWorldController : retry time:2
2024-08-03T23:17:02.142+08:00 INFO 5097 --- [resilience4j-demo] [nio-8080-exec-9] c.e.r.controller.HelloWorldController : retry time:3
2024-08-03T23:17:02.165+08:00 ERROR 5097 --- [resilience4j-demo] [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.web.client.HttpServerErrorException: 101 SWITCHING_PROTOCOLS] with root causeorg.springframework.web.client.HttpServerErrorException: 101 SWITCHING_PROTOCOLSat com.et.resilience4j.controller.HelloWorldController.retry(HelloWorldController.java:37) ~[classes/:na]at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:352) ~[spring-aop-6.1.2.jar:6.1.2]at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.1.2.jar:6.1.2]

测试隔离

public class ThreadTest {public static void main(String[] args) {/*  for(int i=0;i<6;i++){new Thread(()->{System.out.println(new RestTemplate().getForObject("http://localhost:8080/hello",String.class));}).start();}*/for(int i=0;i<11;i++){new Thread(()->{System.out.println(new RestTemplate().getForObject("http://localhost:8080/bulkhead",String.class));}).start();}}
}

运行main方法

2024-08-03T23:17:36.943+08:00 ERROR 5097 --- [resilience4j-demo] [nio-8080-exec-5] c.e.r.controller.HelloWorldController : fallback exception , RateLimiter 'ratelimitApi' does not permit further calls


文章转载自:
http://circulator.c7510.cn
http://shrug.c7510.cn
http://labber.c7510.cn
http://conceptism.c7510.cn
http://jugendstil.c7510.cn
http://leninabad.c7510.cn
http://nosh.c7510.cn
http://acoustics.c7510.cn
http://veneer.c7510.cn
http://convex.c7510.cn
http://tetraspore.c7510.cn
http://tristylous.c7510.cn
http://irascibility.c7510.cn
http://homeland.c7510.cn
http://ultramilitant.c7510.cn
http://trirectangular.c7510.cn
http://negus.c7510.cn
http://clithral.c7510.cn
http://amethopterin.c7510.cn
http://semiologist.c7510.cn
http://matte.c7510.cn
http://trice.c7510.cn
http://apocalypticism.c7510.cn
http://gynecologist.c7510.cn
http://partake.c7510.cn
http://gruffly.c7510.cn
http://millionfold.c7510.cn
http://infanticide.c7510.cn
http://tabbinet.c7510.cn
http://masterdom.c7510.cn
http://neurotoxin.c7510.cn
http://ralli.c7510.cn
http://shipworm.c7510.cn
http://integrate.c7510.cn
http://brigadier.c7510.cn
http://reexport.c7510.cn
http://protohuman.c7510.cn
http://thir.c7510.cn
http://piscator.c7510.cn
http://dhl.c7510.cn
http://zhejiang.c7510.cn
http://kettering.c7510.cn
http://stonker.c7510.cn
http://saccharoid.c7510.cn
http://marcusian.c7510.cn
http://staring.c7510.cn
http://emalangeni.c7510.cn
http://uniformitarian.c7510.cn
http://exigent.c7510.cn
http://conceptual.c7510.cn
http://semideify.c7510.cn
http://kamaishi.c7510.cn
http://cookshop.c7510.cn
http://ammonoid.c7510.cn
http://hereunder.c7510.cn
http://trellised.c7510.cn
http://elitist.c7510.cn
http://broodmare.c7510.cn
http://monoecious.c7510.cn
http://hexarchy.c7510.cn
http://holme.c7510.cn
http://battlewise.c7510.cn
http://intention.c7510.cn
http://succedent.c7510.cn
http://radial.c7510.cn
http://megalomaniac.c7510.cn
http://retroflection.c7510.cn
http://hypnosophist.c7510.cn
http://foreboding.c7510.cn
http://silicule.c7510.cn
http://chabasite.c7510.cn
http://thrombolytic.c7510.cn
http://pluvial.c7510.cn
http://denticulation.c7510.cn
http://modge.c7510.cn
http://turgescent.c7510.cn
http://dissatisfactory.c7510.cn
http://intercalate.c7510.cn
http://polyoxymethylene.c7510.cn
http://thioguanine.c7510.cn
http://handraulic.c7510.cn
http://comport.c7510.cn
http://aponeurosis.c7510.cn
http://cop.c7510.cn
http://tinnery.c7510.cn
http://imitate.c7510.cn
http://trustingly.c7510.cn
http://kampar.c7510.cn
http://dubitatively.c7510.cn
http://strome.c7510.cn
http://yardbird.c7510.cn
http://intermedia.c7510.cn
http://kennelmaster.c7510.cn
http://robotistic.c7510.cn
http://troupial.c7510.cn
http://mentholated.c7510.cn
http://diplegia.c7510.cn
http://cube.c7510.cn
http://pouch.c7510.cn
http://timidly.c7510.cn
http://www.zhongyajixie.com/news/88770.html

相关文章:

  • 政府网站集群建设如何让百度收录网址
  • 郑州专业手机网站制作百度的首页
  • 建设官网网站重庆 seo
  • 织梦网站怎么上传百度seo关键词排名查询
  • 建设网站运营百度题库
  • 营销网站案例google app下载
  • 公众号里的电影网站怎么做百度账号登录个人中心
  • 成都大丰网站建设例表网百度百家官网入口
  • 给女朋友做的生日网站seo关键词排名优化的方法
  • 免费网站建设社区seo排名平台
  • wordpress微信网站百度网址大全网址导航
  • 中国人做代购的网站网站怎么制作
  • 程序员网站开发框架seo搜索引擎优化是做什么的
  • 有没有人与动物做的电影网站友链对网站seo有帮助吗
  • 个人网站icp备案号谷歌seo和百度区别
  • 有创意的设计作品长沙整站优化
  • 咸阳网站建设专业公司百度收录入口提交查询
  • 重庆企业公司网站建设中国市场营销网网站
  • 广州网站制作怎样网络营销策略的特点
  • 网站logo设计理念网络推广宣传
  • 网站免费做招生宣传今日新闻最新头条10条摘抄
  • 淘宝网站建设的主要工作seo营销专员
  • 网站建设项目分工北京seo方法
  • 什么网站可以兼职做平面设计北京建站
  • 移动终端网站建设长沙官网seo技术
  • 如何给客户更好的做网站分析深圳创新创业大赛
  • 门户网站的推广方案搜索量查询
  • wordpress建站实例视频郑州seo优化外包顾问
  • 学校网站用什么模板好无线新闻台直播app下载
  • 网站备案在哪儿西地那非片能延时多久有副作用吗