From a43496b144b7a9ac2500290cb9a81d0d1be08590 Mon Sep 17 00:00:00 2001 From: suncr Date: Thu, 3 Aug 2023 19:54:42 +0800 Subject: [PATCH 1/4] feign client service name cover dubbo provided by --- .../apache/dubbo/config/utils/FeignClientAnnotationUtil.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java index 161cb5a9e58..41b44dd13b3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java @@ -54,9 +54,6 @@ public static void appendParametersFromInterfaceClassMetadata(Class interface return; } - // append old value - serviceName = paramtetersMap.containsKey(PROVIDED_BY) ? paramtetersMap.get(PROVIDED_BY) + "," + serviceName : serviceName; - // cover old value paramtetersMap.put(PROVIDED_BY, serviceName); From bf8ababfa6dda806230d9285c3fb4dc4ada8b219 Mon Sep 17 00:00:00 2001 From: suncr Date: Fri, 4 Aug 2023 12:52:11 +0800 Subject: [PATCH 2/4] add FeignClientAnnotationConfigPostProcessor --- .../apache/dubbo/config/ReferenceConfig.java | 3 -- ...nClientAnnotationConfigPostProcessor.java} | 32 +++++++++++-------- ...rg.apache.dubbo.config.ConfigPostProcessor | 1 + 3 files changed, 20 insertions(+), 16 deletions(-) rename dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/{utils/FeignClientAnnotationUtil.java => processor/FeignClientAnnotationConfigPostProcessor.java} (71%) create mode 100644 dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index e1fe308981c..3018b6cec56 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -34,7 +34,6 @@ import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.config.utils.ConfigValidationUtils; -import org.apache.dubbo.config.utils.FeignClientAnnotationUtil; import org.apache.dubbo.registry.client.metadata.MetadataUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; @@ -419,8 +418,6 @@ private Map appendConfig() { AbstractConfig.appendParameters(map, consumer); AbstractConfig.appendParameters(map, this); appendMetricsCompatible(map); - // after interface metadata set - FeignClientAnnotationUtil.appendParametersFromInterfaceClassMetadata(this.interfaceClass,map); String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY); if (StringUtils.isEmpty(hostToRegistry)) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java similarity index 71% rename from dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java rename to dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java index 41b44dd13b3..b81f7fb6c15 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/FeignClientAnnotationUtil.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java @@ -14,25 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.config.utils; +package org.apache.dubbo.config.processor; +import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.AnnotationUtils; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.ConfigPostProcessor; +import org.apache.dubbo.config.ReferenceConfig; import java.lang.annotation.Annotation; -import java.util.Map; -import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDED_BY; +/** + * parsing @FeignClient service name attribute to replace reference config provided by + */ + +@Activate +public class FeignClientAnnotationConfigPostProcessor implements ConfigPostProcessor { + + @Override + public void postProcessReferConfig(ReferenceConfig referenceConfig) { + appendParametersFromInterfaceClassMetadata(referenceConfig.getInterfaceClass(), referenceConfig); + } + -public class FeignClientAnnotationUtil { - /** - * append parameters from interface class metadata - * such as FeignClient service as dubbo providedBy - * - * @param paramtetersMap - */ - public static void appendParametersFromInterfaceClassMetadata(Class interfaceClass, Map paramtetersMap) { + public static void appendParametersFromInterfaceClassMetadata(Class interfaceClass, ReferenceConfig referenceConfig) { if (interfaceClass == null) { return; @@ -54,8 +60,8 @@ public static void appendParametersFromInterfaceClassMetadata(Class interface return; } - // cover old value - paramtetersMap.put(PROVIDED_BY, serviceName); + referenceConfig.setProvidedBy(serviceName); + } } diff --git a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor new file mode 100644 index 00000000000..0b6f559d366 --- /dev/null +++ b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor @@ -0,0 +1 @@ +feign-provider=org.apache.dubbo.config.processor.FeignClientAnnotationConfigPostProcessor From 874b55ca649708bc1ff59bc4dfb874e45a58d76c Mon Sep 17 00:00:00 2001 From: suncr Date: Fri, 4 Aug 2023 15:29:24 +0800 Subject: [PATCH 3/4] move ConfigPostProcessor to dubbo-common module CommonConfigPostProcessor --- .../config/CommonConfigPostProcessor.java | 36 +++++++++++++++++++ .../dubbo/config/ConfigPostProcessor.java | 5 +-- .../apache/dubbo/config/ReferenceConfig.java | 12 ++++++- .../apache/dubbo/config/ServiceConfig.java | 12 ++++++- ...rg.apache.dubbo.config.ConfigPostProcessor | 1 - ...gnClientAnnotationConfigPostProcessor.java | 14 ++++---- ...che.dubbo.config.CommonConfigPostProcessor | 1 + 7 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/config/CommonConfigPostProcessor.java delete mode 100644 dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor rename {dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor => dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/config}/FeignClientAnnotationConfigPostProcessor.java (83%) create mode 100644 dubbo-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/CommonConfigPostProcessor.java b/dubbo-common/src/main/java/org/apache/dubbo/config/CommonConfigPostProcessor.java new file mode 100644 index 00000000000..fff2a597276 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/CommonConfigPostProcessor.java @@ -0,0 +1,36 @@ +/* + * 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.dubbo.config; + +import org.apache.dubbo.common.extension.ExtensionScope; +import org.apache.dubbo.common.extension.SPI; + +/** + * it will be call when reference or service config refresh + */ + +@SPI(scope = ExtensionScope.MODULE) +public interface CommonConfigPostProcessor { + + default void postProcessReferConfig(ReferenceConfigBase referenceConfig) { + + } + + default void postProcessServiceConfig(ServiceConfigBase serviceConfig) { + + } +} diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigPostProcessor.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigPostProcessor.java index efb779aee71..7e59582ff9b 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigPostProcessor.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigPostProcessor.java @@ -21,10 +21,11 @@ /** * 2019/12/30 + * it will be instead of CommonConfigPostProcessor */ - +@Deprecated @SPI(scope = ExtensionScope.MODULE) -public interface ConfigPostProcessor { +public interface ConfigPostProcessor extends CommonConfigPostProcessor { default void postProcessReferConfig(ReferenceConfig referenceConfig) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 3018b6cec56..73dec83e010 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -58,6 +58,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -792,7 +793,16 @@ protected boolean shouldJvmRefer(Map map) { private void postProcessConfig() { List configPostProcessors = this.getExtensionLoader(ConfigPostProcessor.class) .getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null); - configPostProcessors.forEach(component -> component.postProcessReferConfig(this)); + List commonConfigPostProcessors = this.getExtensionLoader(CommonConfigPostProcessor.class) + .getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null); + + HashSet allConfigPostProcessor = new HashSet<>(); + + // merge common and old config + allConfigPostProcessor.addAll(commonConfigPostProcessors); + allConfigPostProcessor.addAll(configPostProcessors); + + allConfigPostProcessor.forEach(component -> component.postProcessReferConfig(this)); } /** diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 7465c173f6b..8061f7c28d3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -60,6 +60,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.TreeSet; @@ -880,7 +881,16 @@ private boolean isOnlyInJvm() { private void postProcessConfig() { List configPostProcessors = this.getExtensionLoader(ConfigPostProcessor.class) .getActivateExtension(URL.valueOf("configPostProcessor://", getScopeModel()), (String[]) null); - configPostProcessors.forEach(component -> component.postProcessServiceConfig(this)); + List commonConfigPostProcessors = this.getExtensionLoader(CommonConfigPostProcessor.class) + .getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null); + + HashSet allConfigPostProcessor = new HashSet<>(); + + // merge common and old config + allConfigPostProcessor.addAll(commonConfigPostProcessors); + allConfigPostProcessor.addAll(configPostProcessors); + + allConfigPostProcessor.forEach(component -> component.postProcessServiceConfig(this)); } public void addServiceListener(ServiceListener listener) { diff --git a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor b/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor deleted file mode 100644 index 0b6f559d366..00000000000 --- a/dubbo-config/dubbo-config-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.ConfigPostProcessor +++ /dev/null @@ -1 +0,0 @@ -feign-provider=org.apache.dubbo.config.processor.FeignClientAnnotationConfigPostProcessor diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/config/FeignClientAnnotationConfigPostProcessor.java similarity index 83% rename from dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java rename to dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/config/FeignClientAnnotationConfigPostProcessor.java index b81f7fb6c15..8c10e252777 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/processor/FeignClientAnnotationConfigPostProcessor.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/config/FeignClientAnnotationConfigPostProcessor.java @@ -14,31 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.config.processor; +package org.apache.dubbo.rpc.protocol.rest.config; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.AnnotationUtils; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ConfigPostProcessor; -import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.CommonConfigPostProcessor; +import org.apache.dubbo.config.ReferenceConfigBase; import java.lang.annotation.Annotation; /** - * parsing @FeignClient service name attribute to replace reference config provided by + * parsing @FeignClient service name attribute to replace reference config provided by */ @Activate -public class FeignClientAnnotationConfigPostProcessor implements ConfigPostProcessor { +public class FeignClientAnnotationConfigPostProcessor implements CommonConfigPostProcessor { @Override - public void postProcessReferConfig(ReferenceConfig referenceConfig) { + public void postProcessReferConfig(ReferenceConfigBase referenceConfig) { appendParametersFromInterfaceClassMetadata(referenceConfig.getInterfaceClass(), referenceConfig); } - public static void appendParametersFromInterfaceClassMetadata(Class interfaceClass, ReferenceConfig referenceConfig) { + public static void appendParametersFromInterfaceClassMetadata(Class interfaceClass, ReferenceConfigBase referenceConfig) { if (interfaceClass == null) { return; diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor b/dubbo-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor new file mode 100644 index 00000000000..4906a99b7dd --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor @@ -0,0 +1 @@ +feign-provider=org.apache.dubbo.rpc.protocol.rest.config.FeignClientAnnotationConfigPostProcessor From f14f36ada20725cea1d2f800069e9bda5294d3ef Mon Sep 17 00:00:00 2001 From: suncr Date: Fri, 4 Aug 2023 17:12:31 +0800 Subject: [PATCH 4/4] add spi transform --- dubbo-distribution/dubbo-all/pom.xml | 7 +++++++ dubbo-distribution/dubbo-core-spi/pom.xml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index d8bcb04db9a..838b31caee6 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -1551,6 +1551,13 @@ META-INF/dubbo/internal/org.apache.dubbo.common.json.JsonUtil + + + + META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor + + diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index 2a441485f85..06b68c6722e 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -786,6 +786,13 @@ META-INF/dubbo/internal/org.apache.dubbo.validation.Validation + + + + META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor + +