From 2eb5bc08e4229b410cc02b42cd25528eb17d80ff Mon Sep 17 00:00:00 2001 From: manzhizhen Date: Sat, 6 Apr 2019 17:51:39 +0800 Subject: [PATCH] =?UTF-8?q?RpcContext=E6=96=B0=E5=A2=9EremoteApplicationNa?= =?UTF-8?q?me=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/apache/dubbo/rpc/RpcContext.java | 13 +++++++++++++ .../org/apache/dubbo/rpc/filter/ContextFilter.java | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java index 7c10081e5f2..fa63b7e4c1a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java @@ -85,6 +85,9 @@ protected RpcContext initialValue() { private InetSocketAddress localAddress; private InetSocketAddress remoteAddress; + + private String remoteApplicationName; + @Deprecated private List> invokers; @Deprecated @@ -149,6 +152,7 @@ public RpcContext copyOf() { copy.arguments = this.arguments; copy.localAddress = this.localAddress; copy.remoteAddress = this.remoteAddress; + copy.remoteApplicationName = this.remoteApplicationName; copy.invokers = this.invokers; copy.invoker = this.invoker; copy.invocation = this.invocation; @@ -407,6 +411,15 @@ public RpcContext setRemoteAddress(InetSocketAddress address) { return this; } + public String getRemoteApplicationName() { + return remoteApplicationName; + } + + public RpcContext setRemoteApplicationName(String remoteApplicationName) { + this.remoteApplicationName = remoteApplicationName; + return this; + } + /** * get remote address string. * diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index 7f30151d1d1..fe85da0386a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -29,6 +29,8 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.Constants.REMOTE_APPLICATION_KEY; + /** * ContextFilter set the provider RpcContext with invoker, invocation, local port it is using and host for * current execution thread. @@ -59,8 +61,8 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept .setInvoker(invoker) .setInvocation(invocation) // .setAttachments(attachments) // merged from dubbox - .setLocalAddress(invoker.getUrl().getHost(), - invoker.getUrl().getPort()); + .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()) + .setRemoteApplicationName(invoker.getUrl().getParameter(REMOTE_APPLICATION_KEY)); // merged from dubbox // we may already added some attachments into RpcContext before this filter (e.g. in rest protocol)