简体   繁体   中英

how to get the ip and port of the client side for each packet of data on grpc server side which implement by java?

I want to get the client ip and port corresponding to each packet of data by java grpc service.

service Auxiliary {
  rpc ProcessMessage(AuxiliaryGrpcMsgRequest) returns (AuxiliaryGrpcMsgReply) {
  }
}

this method is generated by proto

public void processMessage( AuxiliaryGrpcMsgRequest request, 
           StreamObserver<AuxiliaryGrpcMsgReply> responseObserver) {

}

I want know corresponding IP and port of request. I used ServerInterceptor to get IP, but Interceptor thread is different with this processMessage thread. I don't want to use lock to synchronize the two threads, so I want to see if there is any way to get the ip and port of the client corresponding to the request directly in one thread

I noticed C++ can use context->peer() to achieve this.but java's context have no peer(), is there any way to slove this?

This information is available to interceptors via serverCall.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR) . If you want it in the Context , you'd need to use a ServerInterceptor to copy it to the Context .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM