其他分享
首页 > 其他分享> > ReyClient注解详解

ReyClient注解详解

作者:互联网

ReyClient是x7-reyc框架的注解,通过@ReyClient表示要发起http请求。 x7-reyc封装了httpClient和resilience4j, 注解里可以配置:

value: dns或IP (适合k8s环境下使用)

circuitBreaker: 熔断, ""表示通用配置,"foo", 表示名为foo的专用配置

retry: true表示启用重试,不配置默认为false

fallback: 配置降级类名, 如果配置了, 触发了降级,会去找方法名一样的降级方法,找不到则不执行降级处理

 

特别用法,在方法里增加参数 io.xream.x7.reyc.Url 可以优先替换掉注解里配置的url

 

代码示例:

import io.xream.x7.demo.CatRO;
import io.xream.x7.reyc.Url;
import io.xream.x7.reyc.ReyClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@ReyClient(value = "127.0.0.1:8868", circuitBreaker = "", retry = true, fallback = TestFallback.class)
public interface TestServiceRemote {

@RequestMapping(value = "/xxx/reyc/test") //默认POST请求
Boolean test(CatRO ro, Url url); //参数Url可以优先替换掉注解里配置的url

@RequestMapping(value = "/xxx/time/test", method = RequestMethod.GET)
Boolean testTimeJack();
}


在启动列里要加上注解@EnableReyClient 

配置文件如下:

http.connectTimeout=15000
http.socketTimeout=60000

# 熔断打开的时间 60S, 需要的单独配置的名称: xxxxxx
# resilience4j.circuitbreaker.xxxxxx.waitDurationInOpenState=60000
resilience4j.circuitbreaker.waitDurationInOpenState=60000
resilience4j.circuitbreaker.ringBufferSizeInClosedState=100
resilience4j.circuitbreaker.ringBufferSizeInHalfOpenState=10
resilience4j.circuitbreaker.failureRateThreshold=50
resilience4j.circuitbreaker.eventConsumerBufferSize=100

resilience4j.ratelimiter.limitForPeriod=50
resilience4j.ratelimiter.limitRefreshPeriodInMillis=1
resilience4j.ratelimiter.timeoutInMillis=5000

 

 

标签:circuitbreaker,reyc,详解,import,注解,ReyClient,x7
来源: https://www.cnblogs.com/kkio/p/10838339.html