Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feign client service name cover dubbo provided by #12838

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,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;
Expand Down Expand Up @@ -419,8 +419,6 @@ private Map<String, String> 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)) {
Expand Down Expand Up @@ -795,7 +793,16 @@ protected boolean shouldJvmRefer(Map<String, String> map) {
private void postProcessConfig() {
List<ConfigPostProcessor> configPostProcessors = this.getExtensionLoader(ConfigPostProcessor.class)
.getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null);
configPostProcessors.forEach(component -> component.postProcessReferConfig(this));
List<CommonConfigPostProcessor> commonConfigPostProcessors = this.getExtensionLoader(CommonConfigPostProcessor.class)
.getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null);

HashSet<CommonConfigPostProcessor> allConfigPostProcessor = new HashSet<>();

// merge common and old config
allConfigPostProcessor.addAll(commonConfigPostProcessors);
allConfigPostProcessor.addAll(configPostProcessors);

allConfigPostProcessor.forEach(component -> component.postProcessReferConfig(this));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -880,7 +881,16 @@ private boolean isOnlyInJvm() {
private void postProcessConfig() {
List<ConfigPostProcessor> configPostProcessors = this.getExtensionLoader(ConfigPostProcessor.class)
.getActivateExtension(URL.valueOf("configPostProcessor://", getScopeModel()), (String[]) null);
configPostProcessors.forEach(component -> component.postProcessServiceConfig(this));
List<CommonConfigPostProcessor> commonConfigPostProcessors = this.getExtensionLoader(CommonConfigPostProcessor.class)
.getActivateExtension(URL.valueOf("configPostProcessor://"), (String[]) null);

HashSet<CommonConfigPostProcessor> 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) {
Expand Down
7 changes: 7 additions & 0 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,13 @@
META-INF/dubbo/internal/org.apache.dubbo.common.json.JsonUtil
</resource>
</transformer>

<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor
</resource>
</transformer>
</transformers>
<filters>
<filter>
Expand Down
7 changes: 7 additions & 0 deletions dubbo-distribution/dubbo-core-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,13 @@
META-INF/dubbo/internal/org.apache.dubbo.validation.Validation
</resource>
</transformer>

<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/dubbo/internal/org.apache.dubbo.config.CommonConfigPostProcessor
</resource>
</transformer>
</transformers>
<filters>
<filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.CommonConfigPostProcessor;
import org.apache.dubbo.config.ReferenceConfigBase;

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 CommonConfigPostProcessor {

@Override
public void postProcessReferConfig(ReferenceConfigBase 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<String, String> paramtetersMap) {
public static void appendParametersFromInterfaceClassMetadata(Class<?> interfaceClass, ReferenceConfigBase referenceConfig) {

if (interfaceClass == null) {
return;
Expand All @@ -54,11 +60,8 @@ public static void appendParametersFromInterfaceClassMetadata(Class<?> interface
return;
}

// append old value
serviceName = paramtetersMap.containsKey(PROVIDED_BY) ? paramtetersMap.get(PROVIDED_BY) + "," + serviceName : serviceName;
referenceConfig.setProvidedBy(serviceName);

// cover old value
paramtetersMap.put(PROVIDED_BY, serviceName);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feign-provider=org.apache.dubbo.rpc.protocol.rest.config.FeignClientAnnotationConfigPostProcessor
Loading