From 94e7244eb066eaec6c510583081aa2f14472377a Mon Sep 17 00:00:00 2001 From: xixingya <2679431923@qq.com> Date: Sun, 2 Jul 2023 09:35:28 +0800 Subject: [PATCH] fix the consumer remoteApplication is null (#12635) * fix the consumer remoteApplication is null * fix the consumer remoteApplication is null * fix the consumer remoteApplication is null * fix the consumer remoteApplication is null --- .../rpc/cluster/support/AbstractClusterInvoker.java | 13 ++++++++++++- .../dubbo/rpc/protocol/dubbo/DubboInvoker.java | 3 --- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index 861f5ab789..745e602f1f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -379,7 +379,7 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { if (ProfilerSwitch.isEnableSimpleProfiler()) { InvocationProfilerUtils.enterProfiler(invocation, "Invoker invoke. Target Address: " + invoker.getUrl().getAddress()); } - invocation.addInvokedInvoker(invoker); + setRemote(invoker, invocation); result = invoker.invoke(invocation); } finally { clearContext(originInvoker); @@ -388,6 +388,17 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { return result; } + /** + * Set the remoteAddress and remoteApplicationName so that filter can get them. + * + */ + private void setRemote(Invoker invoker, Invocation invocation) { + invocation.addInvokedInvoker(invoker); + RpcServiceContext serviceContext = RpcContext.getServiceContext(); + serviceContext.setRemoteAddress(invoker.getUrl().toInetSocketAddress()); + serviceContext.setRemoteApplicationName(invoker.getUrl().getRemoteApplication()); + } + /** * When using a thread pool to fork a child thread, ThreadLocal cannot be passed. * In this scenario, please use the invokeWithContextAsync method. diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 06466c6938..64ec05dc8f 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -34,7 +34,6 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.InvokeMode; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; -import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.protocol.AbstractInvoker; @@ -111,8 +110,6 @@ public class DubboInvoker extends AbstractInvoker { invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); - RpcContext.getServiceContext().setRemoteAddress(currentClient.getRemoteAddress()); - Integer payload = getUrl().getParameter(PAYLOAD, Integer.class); Request request = new Request();