Fix local invoke consumer url override (#12553)

This commit is contained in:
Albumen Kevin 2023-06-19 09:34:29 +08:00 committed by GitHub
parent 3160602072
commit a4e9c9efa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -20,6 +20,7 @@ package org.apache.dubbo.rpc.cluster.support.wrapper;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.url.component.DubboServiceAddressURL;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Exporter;
@ -179,7 +180,7 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
}
if (getUrl().getServiceKey().equals(exporter.getInvoker().getUrl().getServiceKey())
&& exporter.getInvoker().getUrl().getProtocol().equalsIgnoreCase(LOCAL_PROTOCOL)) {
createInjvmInvoker();
createInjvmInvoker(exporter);
isExported.compareAndSet(false, true);
}
}
@ -275,14 +276,19 @@ public class ScopeClusterInvoker<T> implements ClusterInvoker<T>, ExporterChange
/**
* Creates a new Invoker for the current ScopeClusterInvoker and exports it to the local JVM.
*/
private void createInjvmInvoker() {
private void createInjvmInvoker(Exporter<?> exporter) {
if (injvmInvoker == null) {
synchronized (createLock) {
if (injvmInvoker == null) {
URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(), getInterface().getName(), getUrl().getParameters());
URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(),
getInterface().getName(), getUrl().getParameters());
url = url.setScopeModel(getUrl().getScopeModel());
url = url.setServiceModel(getUrl().getServiceModel());
Invoker<?> invoker = protocolSPI.refer(getInterface(), url);
DubboServiceAddressURL consumerUrl = new DubboServiceAddressURL(url.getUrlAddress(), url.getUrlParam(),
exporter.getInvoker().getUrl(), null);
Invoker<?> invoker = protocolSPI.refer(getInterface(), consumerUrl);
List<Invoker<?>> invokers = new ArrayList<>();
invokers.add(invoker);
injvmInvoker = Cluster.getCluster(url.getScopeModel(), Cluster.DEFAULT, false).join(new StaticDirectory(url, invokers), true);

View File

@ -229,7 +229,7 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
if (pts != null && args != null && pts.length == args.length) {
realArgument = new Object[pts.length];
for (int i = 0; i < pts.length; i++) {
realArgument[i] = paramDeepCopyUtil.copy(invoker.getUrl(), args[i], pts[i]);
realArgument[i] = paramDeepCopyUtil.copy(getUrl(), args[i], pts[i]);
}
}
if (realArgument == null) {