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

grpc server interceptor #437

Merged
merged 2 commits into from
May 9, 2020
Merged

Conversation

SteNicholas
Copy link
Contributor

No description provided.

final ServerCallHandler<Message, Message> handler = ServerCalls.asyncUnaryCall(
(request, responseObserver) -> {
final RpcContext rpcCtx = new RpcContext() {

Copy link
Contributor

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();
Copy link
Contributor

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,
Copy link
Contributor

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.
Copy link
Contributor

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"),
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字可以改一下,更专项一些

@fengjiachun fengjiachun merged commit ad223d4 into sofastack:feat/grpc_impl May 9, 2020
fengjiachun pushed a commit that referenced this pull request May 9, 2020
* grpc server interceptor
fengjiachun pushed a commit that referenced this pull request May 9, 2020
* grpc server interceptor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants