Reputation: 1
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?
Upvotes: 0
Views: 1561
Reputation: 26394
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
.
Upvotes: 1