This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 00ecc82  [type:refactor][ISSUE #2916]change ribbon default 
ServerListRefreshInterval from 30s to 10s (#2922)
00ecc82 is described below

commit 00ecc8291f0f557a0f42dc4b285c4613d3422043
Author: dragon-zhang <[email protected]>
AuthorDate: Wed Feb 23 10:54:42 2022 +0800

    [type:refactor][ISSUE #2916]change ribbon default ServerListRefreshInterval 
from 30s to 10s (#2922)
    
    * [type:refactor][ISSUE #2916]change ribbon default 
ServerListRefreshInterval from 30s to 10s
    
    * rollback code format
---
 .../src/main/resources/application.yml             |  2 +
 .../apache/shenyu/common/config/ShenyuConfig.java  | 66 +++++++++++++++++++++-
 .../SpringCloudPluginConfiguration.java            | 17 ++++++
 3 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/shenyu-bootstrap/src/main/resources/application.yml 
b/shenyu-bootstrap/src/main/resources/application.yml
index 171b32c..b3b1a4c 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -154,6 +154,8 @@ shenyu:
     interval: 5000
     printEnabled: true
     printInterval: 60000
+  ribbon:
+    serverListRefreshInterval: 10000
 
 eureka:
   client:
diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java 
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
index 9b5947f..41ba24e 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
@@ -49,7 +49,27 @@ public class ShenyuConfig {
     private CrossFilterConfig cross = new CrossFilterConfig();
     
     private InstanceConfig instance = new InstanceConfig();
-    
+
+    private RibbonConfig ribbon = new RibbonConfig();
+
+    /**
+     * Gets ribbon.
+     *
+     * @return the ribbon
+     */
+    public RibbonConfig getRibbon() {
+        return ribbon;
+    }
+
+    /**
+     * Sets ribbon.
+     *
+     * @param ribbon the ribbon
+     */
+    public void setRibbon(final RibbonConfig ribbon) {
+        this.ribbon = ribbon;
+    }
+
     /**
      * Gets instance.
      *
@@ -986,4 +1006,48 @@ public class ShenyuConfig {
             this.props = props;
         }
     }
+
+    /**
+     * The Ribbon Config.
+     */
+    public static class RibbonConfig {
+
+        /**
+         * see {@code 
com.netflix.client.config.CommonClientConfigKey#ServerListRefreshInterval}.
+         */
+        private Integer serverListRefreshInterval = 10000;
+
+        /**
+         * Instantiates a new RibbonConfig.
+         */
+        public RibbonConfig() {
+        }
+
+        /**
+         * Instantiates a new RibbonConfig.
+         *
+         * @param serverListRefreshInterval serverListRefreshInterval
+         */
+        public RibbonConfig(final Integer serverListRefreshInterval) {
+            this.serverListRefreshInterval = serverListRefreshInterval;
+        }
+
+        /**
+         * Gets serverListRefreshInterval.
+         *
+         * @return the serverListRefreshInterval
+         */
+        public Integer getServerListRefreshInterval() {
+            return serverListRefreshInterval;
+        }
+
+        /**
+         * setServerListRefreshInterval.
+         *
+         * @param serverListRefreshInterval serverListRefreshInterval
+         */
+        public void setServerListRefreshInterval(final Integer 
serverListRefreshInterval) {
+            this.serverListRefreshInterval = serverListRefreshInterval;
+        }
+    }
 }
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-springcloud/src/main/java/org/apache/shenyu/springboot/starter/plugin/springcloud/SpringCloudPluginConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-springcloud/src/main/java/org/apache/shenyu/springboot/starter/plugin/springcloud/SpringCloudPluginConfiguration.java
index 8f31c4b..5634819 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-springcloud/src/main/java/org/apache/shenyu/springboot/starter/plugin/springcloud/SpringCloudPluginConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-springcloud/src/main/java/org/apache/shenyu/springboot/starter/plugin/springcloud/SpringCloudPluginConfiguration.java
@@ -17,7 +17,12 @@
 
 package org.apache.shenyu.springboot.starter.plugin.springcloud;
 
+import com.netflix.client.config.CommonClientConfigKey;
+import com.netflix.client.config.IClientConfig;
 import com.netflix.loadbalancer.IRule;
+import com.netflix.loadbalancer.PollingServerListUpdater;
+import com.netflix.loadbalancer.ServerListUpdater;
+import org.apache.shenyu.common.config.ShenyuConfig;
 import org.apache.shenyu.common.constant.Constants;
 import org.apache.shenyu.plugin.api.ShenyuPlugin;
 import org.apache.shenyu.plugin.api.context.ShenyuContextDecorator;
@@ -31,6 +36,9 @@ import 
org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
 import org.springframework.cloud.netflix.ribbon.RibbonClientSpecification;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+import java.util.Optional;
 
 /**
  * The type Spring cloud plugin configuration.
@@ -85,6 +93,15 @@ public class SpringCloudPluginConfiguration {
         public IRule ribbonRule() {
             return new LoadBalanceRule();
         }
+
+        @Lazy
+        @Bean
+        public ServerListUpdater ribbonServerListUpdater(final IClientConfig 
config,
+                                                         final ShenyuConfig 
shenyuConfig) {
+            Integer refreshInterval = 
Optional.ofNullable(shenyuConfig.getRibbon().getServerListRefreshInterval()).orElseGet(()
 -> 10000);
+            config.set(CommonClientConfigKey.ServerListRefreshInterval, 
refreshInterval);
+            return new PollingServerListUpdater(config);
+        }
     }
 
 }

Reply via email to