forked from LianjiaTech/retrofit-spring-boot-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LianjiaTech#105 from DawnSouther/master
熔断限流组件优化集成逻辑
- Loading branch information
Showing
18 changed files
with
404 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,21 @@ | |
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author 陈添明 | ||
* 应仅采用异常比例模式来控制熔断,超时导致的报错应在okhttp这一层做 | ||
* @author 陈添明 [email protected] | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
@Documented | ||
public @interface Degrade { | ||
|
||
/** | ||
* RT threshold or exception ratio threshold count. | ||
* 异常比例 | ||
*/ | ||
double count(); | ||
float count(); | ||
|
||
/** | ||
* Degrade recover timeout (in seconds) when degradation occurs. | ||
* 时间窗口size,单位:秒 | ||
*/ | ||
int timeWindow() default 5; | ||
|
||
/** | ||
* Degrade strategy (0: average RT, 1: exception ratio). | ||
*/ | ||
DegradeStrategy degradeStrategy() default DegradeStrategy.AVERAGE_RT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/github/lianjiatech/retrofit/spring/boot/degrade/DegradeRuleRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.lianjiatech.retrofit.spring.boot.degrade; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import okhttp3.Response; | ||
|
||
/** | ||
* @author [email protected] 2022/4/5 23:14 | ||
*/ | ||
public interface DegradeRuleRegister { | ||
|
||
/** | ||
* 批量注册规则 | ||
* @param retrofitDegradeRuleList 规则描述对象集合 | ||
*/ | ||
void batchRegister(List<RetrofitDegradeRule> retrofitDegradeRuleList); | ||
|
||
/** | ||
* 使用规则代理执行目标方法 | ||
* @param resourceName 资源名称 | ||
* @param func 目标方法 | ||
* @return okhttp响应 | ||
* @throws IOException IOException | ||
*/ | ||
Response exec(String resourceName, DegradeProxyMethod<Response> func) throws IOException; | ||
|
||
@FunctionalInterface | ||
interface DegradeProxyMethod<R>{ | ||
R get() throws IOException; | ||
} | ||
} |
Oops, something went wrong.