File tree Expand file tree Collapse file tree
core-impl/client/src/main/java/com/alipay/sofa/rpc/client
api/src/main/java/com/alipay/sofa/rpc/filter
exception/src/main/java/com/alipay/sofa/rpc/core/exception Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,6 +67,15 @@ public SofaResponse doInvoke(SofaRequest request) throws SofaRpcException {
6767 providerInfo = select (request , invokedProviderInfos );
6868 SofaResponse response = filterChain (providerInfo , request );
6969 if (response != null ) {
70+ // 检查是否是用户自定义的可重试异常
71+ Object appResponse = response .getAppResponse ();
72+ if (appResponse instanceof SofaRpcException ) {
73+ if (((SofaRpcException ) appResponse ).getErrorType () == RpcErrorType .CUSTOMER_RETRY_ERROR ) {
74+ time ++;
75+ throwable = (SofaRpcException ) appResponse ;
76+ continue ;
77+ }
78+ }
7079 if (throwable != null ) {
7180 if (LOGGER .isWarnEnabled (consumerConfig .getAppName ())) {
7281 LOGGER .warnWithApp (consumerConfig .getAppName (),
Original file line number Diff line number Diff line change 1717package com .alipay .sofa .rpc .filter ;
1818
1919import com .alipay .sofa .rpc .common .RpcConstants ;
20+ import com .alipay .sofa .rpc .common .annotation .RetryableException ;
2021import com .alipay .sofa .rpc .config .ProviderConfig ;
2122import com .alipay .sofa .rpc .context .RpcInternalContext ;
2223import com .alipay .sofa .rpc .context .RpcInvokeContext ;
@@ -113,7 +114,12 @@ public SofaResponse invoke(SofaRequest request) throws SofaRpcException {
113114 // sofaResponse.setErrorMsg(e.getMessage());
114115 } catch (InvocationTargetException e ) { // 业务代码抛出异常
115116 cutCause (e .getCause ());
116- sofaResponse .setAppResponse (e .getCause ());
117+ // 查看该异常是否被用户声明为可重试异常
118+ if (e .getCause ().getClass ().isAnnotationPresent (RetryableException .class )) {
119+ sofaResponse .setAppResponse (new SofaRpcException (RpcErrorType .CUSTOMER_RETRY_ERROR , e .getCause ()));
120+ } else {
121+ sofaResponse .setAppResponse (e .getCause ());
122+ }
117123 } finally {
118124 // R8: Record business processing execution time
119125 if (RpcInternalContext .isAttachmentEnable ()) {
Original file line number Diff line number Diff line change @@ -107,4 +107,9 @@ public class RpcErrorType {
107107 * 客户端未定义异常
108108 */
109109 public static final int CLIENT_UNDECLARED_ERROR = 299 ;
110+
111+ /**
112+ * 用户自定义可重试异常
113+ */
114+ public static final int CUSTOMER_RETRY_ERROR = 300 ;
110115}
You can’t perform that action at this time.
0 commit comments