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
This commit is contained in:
xixingya 2023-07-02 09:35:28 +08:00 committed by GitHub
parent 70a948a3d4
commit 94e7244eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -379,7 +379,7 @@ public abstract class AbstractClusterInvoker<T> implements ClusterInvoker<T> {
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<T> implements ClusterInvoker<T> {
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.

View File

@ -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<T> extends AbstractInvoker<T> {
invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout));
RpcContext.getServiceContext().setRemoteAddress(currentClient.getRemoteAddress());
Integer payload = getUrl().getParameter(PAYLOAD, Integer.class);
Request request = new Request();