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

Java brpc client 如何获取 远端的ip port #236

Closed
welsonzhang opened this issue Jan 19, 2022 · 2 comments
Closed

Java brpc client 如何获取 远端的ip port #236

welsonzhang opened this issue Jan 19, 2022 · 2 comments

Comments

@welsonzhang
Copy link

welsonzhang commented Jan 19, 2022

rpc 调用之后,想知道调用远端的ip port,
从rpc上下文获取到的接口发现都是null的
RpcContext.getContext().getChannel()
RpcContext.getContext().getRemoteAddress()

@welsonzhang welsonzhang changed the title Java brpc client 如何获取 远端的ip port Java brpc client 如何获取 远端的ip port, C++版本获取远端的ip port还是挺简单的 Jan 19, 2022
@welsonzhang welsonzhang changed the title Java brpc client 如何获取 远端的ip port, C++版本获取远端的ip port还是挺简单的 Java brpc client 如何获取 远端的ip port Mar 1, 2022
@welsonzhang
Copy link
Author

welsonzhang commented Mar 1, 2022

只能自己新建一个Brpc Proxy,在里面添加对应的代码:

                if (request.getCommunicationClient() != null) {
                    SocketAddress socketAddress = new InetSocketAddress(
                            request.getCommunicationClient().getServiceInstance().getIp(),
                            request.getCommunicationClient().getServiceInstance().getPort());
                    RpcContext.getContext().setRemoteAddress(socketAddress);
                }
                currentTryTimes++;
            } 

@tullyliu tullyliu closed this as completed Oct 3, 2022
@Sleaon
Copy link

Sleaon commented Nov 30, 2022

可以加一个Interceptor , 在拦截器里面获取 request.getCommunicationClient().getServiceInstance().getIp()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants