⏪ 回滚feign 自动降级的逻辑,方便调用方异常处理
This commit is contained in:
1 parent
cc1a87944b
commit
e50fb137e7
2 files changed
+6
-1
No files matched your search
+1
-1
@@ -46,7 +46,7 @@ public class PigxSentinelAutoConfiguration {
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled")
|
||||
@ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled",matchIfMissing = true)
|
||||
public Feign.Builder feignSentinelBuilder() {
|
||||
return PigxSentinelFeign.builder();
|
||||
}
|
||||
|
||||
+5
@@ -8,6 +8,7 @@ import com.alibaba.csp.sentinel.SphU;
|
||||
import com.alibaba.csp.sentinel.Tracer;
|
||||
import com.alibaba.csp.sentinel.context.ContextUtil;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import feign.Feign;
|
||||
import feign.InvocationHandlerFactory;
|
||||
import feign.MethodMetadata;
|
||||
@@ -118,6 +119,10 @@ public class PigxSentinelInvocationHandler implements InvocationHandler {
|
||||
throw new AssertionError(e.getCause());
|
||||
}
|
||||
}
|
||||
else if (R.class == method.getReturnType()) {
|
||||
log.error("feign 服务间调用异常", ex);
|
||||
return R.failed(ex.getLocalizedMessage());
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user