You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/04/02 13:20:48 UTC

[incubator-linkis] branch dev-1.1.2 updated: RPC support modifying parameters such as Ribbon #1887 (#1894)

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

casion pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
     new 654b3a6  RPC  support modifying parameters such as Ribbon #1887 (#1894)
654b3a6 is described below

commit 654b3a6f28541e979d9a1fb3fcf6a92494452b57
Author: peacewong <wp...@gmail.com>
AuthorDate: Sat Apr 2 21:20:42 2022 +0800

    RPC  support modifying parameters such as Ribbon #1887 (#1894)
---
 .../message/utils/LoadBalancerOptionsUtils.java    | 43 ++++++++++++++++++++++
 .../linkis/rpc/sender/SpringMVCRPCSender.scala     |  3 +-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/utils/LoadBalancerOptionsUtils.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/utils/LoadBalancerOptionsUtils.java
new file mode 100644
index 0000000..f4d3adf
--- /dev/null
+++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/message/utils/LoadBalancerOptionsUtils.java
@@ -0,0 +1,43 @@
+/*
+ * 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.linkis.rpc.message.utils;
+
+import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
+
+import feign.Request.Options;
+
+import java.lang.reflect.Field;
+
+public class LoadBalancerOptionsUtils {
+
+    private static Options DEFAULT_OPTIONS = null;
+
+    private static Object locker = new Object();
+
+    public static Options getDefaultOptions() throws NoSuchFieldException, IllegalAccessException {
+        if (null == DEFAULT_OPTIONS)
+            synchronized (locker) {
+                Class<?> clazz = LoadBalancerFeignClient.class;
+                Field optionField = clazz.getDeclaredField("DEFAULT_OPTIONS");
+                optionField.setAccessible(true);
+                Object o = optionField.get(clazz);
+                DEFAULT_OPTIONS = (Options) o;
+            }
+        return DEFAULT_OPTIONS;
+    }
+}
diff --git a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/sender/SpringMVCRPCSender.scala b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/sender/SpringMVCRPCSender.scala
index 28df35f..fcf7f55 100644
--- a/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/sender/SpringMVCRPCSender.scala
+++ b/linkis-commons/linkis-rpc/src/main/scala/org/apache/linkis/rpc/sender/SpringMVCRPCSender.scala
@@ -18,7 +18,6 @@
 package org.apache.linkis.rpc.sender
 
 import java.lang.reflect.Field
-
 import com.netflix.client.ClientRequest
 import com.netflix.client.config.IClientConfig
 import com.netflix.loadbalancer.reactive.LoadBalancerCommand
@@ -31,6 +30,7 @@ import org.apache.linkis.rpc.{BaseRPCSender, RPCMessageEvent, RPCSpringBeanCache
 import org.apache.linkis.server.{BDPJettyServerHelper, Message}
 import feign._
 import org.apache.commons.lang.StringUtils
+import org.apache.linkis.rpc.message.utils.LoadBalancerOptionsUtils
 import org.springframework.cloud.netflix.ribbon.ServerIntrospector
 import org.springframework.cloud.openfeign.ribbon.{CachingSpringLoadBalancerFactory, FeignLoadBalancer, LoadBalancerFeignClient}
 
@@ -78,6 +78,7 @@ private[rpc] class SpringMVCRPCSender private[rpc](private[rpc] val serviceInsta
         }
       }
     }, getClientFactory)
+    builder.options(LoadBalancerOptionsUtils.getDefaultOptions)
     super.doBuilder(builder)
     builder.contract(getContract)
       .encoder(getEncoder).decoder(getDecoder)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org