-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
grpc server interceptor #437
Conversation
f0241ef
to
e30a376
Compare
final ServerCallHandler<Message, Message> handler = ServerCalls.asyncUnaryCall( | ||
(request, responseObserver) -> { | ||
final RpcContext rpcCtx = new RpcContext() { | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式
@Override | ||
public String getRemoteAddress() { | ||
return null; | ||
return Context.key("remoteAddress").get().toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remoteAddress 定义常量
public class GrpcServerInterceptor implements ServerInterceptor { | ||
|
||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
import io.grpc.ServerInterceptor; | ||
|
||
/** | ||
* GRPC RPC server interceptor to trace remote address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RPC 可以去掉
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, | ||
ServerCallHandler<ReqT, RespT> serverCallHandler) { | ||
Context context = Context.current().withValue(Context.key("remoteAddress"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
* | ||
* @author nicholas.jxf | ||
*/ | ||
public class GrpcServerInterceptor implements ServerInterceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
名字可以改一下,更专项一些
No description provided.