Aias00 commented on code in PR #5969:
URL: https://github.com/apache/shenyu/pull/5969#discussion_r2011148235


##########
shenyu-common/src/main/java/org/apache/shenyu/common/enums/HttpRetryBackoffSpecEnum.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.enums;
+
+import java.util.Arrays;
+
+/**
+ * The http scheme enum.
+ */
+public enum HttpRetryBackoffSpecEnum {
+
+    /**
+     * 默认重试.
+     */
+    DEFAULT_BACKOFF("default"),
+
+    /**
+     * 固定重试.
+     */
+    FIXED_BACKOFF("fixed"),
+
+    /**
+     * 指数重试.

Review Comment:
   use English, pls



##########
shenyu-common/src/main/java/org/apache/shenyu/common/enums/HttpRetryBackoffSpecEnum.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.enums;
+
+import java.util.Arrays;
+
+/**
+ * The http scheme enum.
+ */
+public enum HttpRetryBackoffSpecEnum {
+
+    /**
+     * 默认重试.
+     */
+    DEFAULT_BACKOFF("default"),
+
+    /**
+     * 固定重试.

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/DefaultRetryStrategy.java:
##########
@@ -0,0 +1,117 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.enums.RetryEnum;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
+import org.apache.shenyu.loadbalancer.entity.Upstream;
+import org.apache.shenyu.loadbalancer.factory.LoadBalancerFactory;
+import org.apache.shenyu.plugin.api.utils.RequestUrlUtils;
+import org.apache.shenyu.plugin.httpclient.exception.ShenyuTimeoutException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.server.ResponseStatusException;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
+import reactor.util.retry.RetryBackoffSpec;
+
+import java.net.URI;
+import java.time.Duration;
+import java.util.*;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+
+
+/**
+ * 默认重试策略类 Default Retry Policy Class

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/CustomRetryStrategy.java:
##########
@@ -0,0 +1,37 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.time.Duration;
+
+/**
+ * 自定义重试策略 Custom retry policy

Review Comment:
   use English, pls



##########
shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java:
##########
@@ -960,7 +960,11 @@ public interface Constants {
      * The constant Content-Encoding.
      */
     String CONTENT_ENCODING = "Content-Encoding";
-    
+    /**
+     * http请求重试策略  http request retry policy.

Review Comment:
   use English, pls



##########
shenyu-common/src/main/java/org/apache/shenyu/common/enums/HttpRetryBackoffSpecEnum.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.enums;
+
+import java.util.Arrays;
+
+/**
+ * The http scheme enum.
+ */
+public enum HttpRetryBackoffSpecEnum {
+
+    /**
+     * 默认重试.

Review Comment:
   use English, pls



##########
shenyu-common/src/main/java/org/apache/shenyu/common/enums/HttpRetryBackoffSpecEnum.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.enums;
+
+import java.util.Arrays;
+
+/**
+ * The http scheme enum.
+ */
+public enum HttpRetryBackoffSpecEnum {
+
+    /**
+     * 默认重试.
+     */
+    DEFAULT_BACKOFF("default"),
+
+    /**
+     * 固定重试.
+     */
+    FIXED_BACKOFF("fixed"),
+
+    /**
+     * 指数重试.
+     */
+    EXPONENTIAL_BACKOFF("exponential"),
+
+    /**
+     * 自定义重试.

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/CustomRetryStrategy.java:
##########
@@ -0,0 +1,37 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.time.Duration;
+
+/**
+ * 自定义重试策略 Custom retry policy
+ *      还请自己实现
+ *@author Jerry
+ *@Date 2025/3/23 14:27
+ */
+public class CustomRetryStrategy<R> implements RetryStrategy<R> {
+    private final AbstractHttpClientPlugin<R> httpClientPlugin;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CustomRetryStrategy.class);
+
+    public CustomRetryStrategy(AbstractHttpClientPlugin<R> httpClientPlugin) {
+        this.httpClientPlugin = httpClientPlugin;
+    }
+
+    /**
+     * 自定义重试策略 Custom retry policy

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java:
##########
@@ -88,80 +73,31 @@ public final Mono<Void> execute(final ServerWebExchange 
exchange, final ShenyuPl
         final Mono<R> response = doRequest(exchange, 
exchange.getRequest().getMethod().name(), uri, exchange.getRequest().getBody())
                 .timeout(duration, Mono.error(() -> new 
TimeoutException("Response took longer than timeout: " + duration)))
                 .doOnError(e -> LOG.error(e.getMessage(), e));
-        if (RetryEnum.CURRENT.getName().equals(retryStrategy)) {
-            //old version of DividePlugin and SpringCloudPlugin will run on 
this
-            RetryBackoffSpec retryBackoffSpec = Retry.backoff(retryTimes, 
Duration.ofMillis(20L))
-                    .maxBackoff(Duration.ofSeconds(20L))
-                    .transientErrors(true)
-                    .jitter(0.5d)
-                    .filter(t -> t instanceof TimeoutException || t instanceof 
ConnectTimeoutException
-                            || t instanceof ReadTimeoutException || t 
instanceof IllegalStateException)
-                    .onRetryExhaustedThrow((retryBackoffSpecErr, retrySignal) 
-> {
-                        throw new ShenyuTimeoutException("Request timeout, the 
maximum number of retry times has been exceeded");
-                    });
-            return response.retryWhen(retryBackoffSpec)
-                    .onErrorMap(ShenyuTimeoutException.class, th -> new 
ResponseStatusException(HttpStatus.REQUEST_TIMEOUT, th.getMessage(), th))
-                    .onErrorMap(TimeoutException.class, th -> new 
ResponseStatusException(HttpStatus.GATEWAY_TIMEOUT, th.getMessage(), th))
-                    .flatMap((Function<Object, Mono<? extends Void>>) o -> 
chain.execute(exchange));
+
+        RetryStrategy<R> strategy;
+        //这里走配置文件是不是更好点?   Is it better to go with the configuration file here?

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/FixedRetryStrategy.java:
##########
@@ -0,0 +1,43 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
+
+import java.time.Duration;
+
+/**
+ * @author Jerry
+ * @Date 2025/3/23 10:04
+ */
+public class FixedRetryStrategy<R> implements RetryStrategy<R> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(FixedRetryStrategy.class);
+
+    private final AbstractHttpClientPlugin<R> httpClientPlugin;
+
+    public FixedRetryStrategy(AbstractHttpClientPlugin<R> httpClientPlugin) {
+        this.httpClientPlugin = httpClientPlugin;
+    }
+
+    /**
+     * 执行重试策略

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/RetryStrategy.java:
##########
@@ -0,0 +1,26 @@
+package org.apache.shenyu.plugin.httpclient;
+
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.time.Duration;
+
+/**
+ * 重试策略接口 Retry Policy Interface

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/CustomRetryStrategy.java:
##########
@@ -0,0 +1,37 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.time.Duration;
+
+/**
+ * 自定义重试策略 Custom retry policy
+ *      还请自己实现

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/CustomRetryStrategy.java:
##########
@@ -0,0 +1,37 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.time.Duration;
+
+/**
+ * 自定义重试策略 Custom retry policy
+ *      还请自己实现
+ *@author Jerry
+ *@Date 2025/3/23 14:27
+ */
+public class CustomRetryStrategy<R> implements RetryStrategy<R> {
+    private final AbstractHttpClientPlugin<R> httpClientPlugin;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CustomRetryStrategy.class);
+
+    public CustomRetryStrategy(AbstractHttpClientPlugin<R> httpClientPlugin) {
+        this.httpClientPlugin = httpClientPlugin;
+    }
+
+    /**
+     * 自定义重试策略 Custom retry policy
+     *
+     * @param response   响应的 Mono 对象 The Mono object of the response
+     * @param exchange   当前服务器交换对象 Current Server Exchange Object
+     * @param duration   超时时间 Timeout
+     * @param retryTimes 重试次数 Number of retries
+     * @return 经过重试处理后的响应 Mono 对象 Response Mono object after retry processing

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/ExponentialRetryBackoffStrategy.java:
##########
@@ -0,0 +1,54 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
+import reactor.util.retry.RetryBackoffSpec;
+
+import java.time.Duration;
+
+/**
+ * @author Jerry
+ * @Date 2025/3/23 14:20
+ */
+public class ExponentialRetryBackoffStrategy<R> implements RetryStrategy<R> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(ExponentialRetryBackoffStrategy.class);
+
+    private final AbstractHttpClientPlugin<R> httpClientPlugin;
+
+    public ExponentialRetryBackoffStrategy(AbstractHttpClientPlugin<R> 
httpClientPlugin) {
+        this.httpClientPlugin = httpClientPlugin;
+    }
+
+    /**
+     * 执行重试策略

Review Comment:
   use English, pls



##########
shenyu-plugin/shenyu-plugin-httpclient/src/test/java/org/apache/shenyu/plugin/httpclient/RetryStrategyTest.java:
##########
@@ -0,0 +1,86 @@
+package org.apache.shenyu.plugin.httpclient;
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * @author Jerry
+ * @Date 2025/3/16 22:46
+ */
+public class RetryStrategyTest{
+
+    @Test
+    void testDefaultRetryBackoffExecute() {
+        // 创建一个模拟的 AbstractHttpClientPlugin

Review Comment:
   use English, pls



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to