public static void main(String[] args) { String jwt = createJwt(Constant.JWT_SECRET, "authClient", "rayt"); //String jwt = createJwt("123124123", "authClient", "rayt"); System.out.println("Created a JWT: " + jwt); JwtCallCredential callCredential = new JwtCallCredential(jwt); ManagedChannel greetingChannel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new TraceIdClientInterceptor()) .build(); ManagedChannel goodbyeChannel = ManagedChannelBuilder.forAddress("localhost", 9090) .usePlaintext(true) .intercept(new TraceIdClientInterceptor()) .build(); Context.current().withValue(Constant.TRACE_ID_CTX_KEY, "1").run(() -> { GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(greetingChannel).withCallCredentials(callCredential); HelloResponse helloResponse = greetingStub.greeting(HelloRequest.newBuilder().setName("Ray").build()); System.out.println(helloResponse); }); Context.current().withValue(Constant.TRACE_ID_CTX_KEY, "2").run(() -> { GoodbyeServiceGrpc.GoodbyeServiceBlockingStub goodbyeStub = GoodbyeServiceGrpc.newBlockingStub(goodbyeChannel).withCallCredentials(callCredential); GoodbyeResponse goodbyeResponse = goodbyeStub.goodbye(GoodbyeRequest.newBuilder().setName("Jason").build()); System.out.println(goodbyeResponse); }); }
public static void main(String[] args) throws InterruptedException { ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub stub = GreetingServiceGrpc.newBlockingStub(channel); HelloResponse helloResponse = stub.greeting( HelloRequest.newBuilder() .setName("Ray") .setAge(18) .setSentiment(Sentiment.HAPPY) .build()); System.out.println(helloResponse); channel.shutdown(); } }
@java.lang.Override protected GreetingServiceBlockingStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new GreetingServiceBlockingStub(channel, callOptions); }
/** * Creates a new blocking-style stub that supports unary and streaming output calls on the service */ public static GreetingServiceBlockingStub newBlockingStub( io.grpc.Channel channel) { return new GreetingServiceBlockingStub(channel); }
@Override public void goodbye(GoodbyeRequest request, StreamObserver<GoodbyeResponse> responseObserver) { HelloResponse helloResponse = this.greetingStub.greeting(HelloRequest.newBuilder().setName(request.getName()).build()); System.out.println(helloResponse); String farewell = helloResponse.getGreeting() + ", and goodbye, " + request.getName(); responseObserver.onNext(GoodbyeResponse.newBuilder().setFarewell(farewell).build()); responseObserver.onCompleted(); } }
/** * Creates a new blocking-style stub that supports unary and streaming output calls on the service */ public static GreetingServiceBlockingStub newBlockingStub( io.grpc.Channel channel) { return new GreetingServiceBlockingStub(channel); }
@Override public void goodbye(GoodbyeRequest request, StreamObserver<GoodbyeResponse> responseObserver) { String userId = Constant.USER_ID_CTX_KEY.get(); System.out.println("Goodbye Service Trace ID: " + Constant.TRACE_ID_CTX_KEY.get()); System.out.println("Goodbye Service User ID: " + userId); HelloResponse helloResponse = this.greetingStub.greeting(HelloRequest.newBuilder().setName(request.getName()).build()); System.out.println(helloResponse); String farewell = "Goodye, " + request.getName() + ", your userId is " + userId; responseObserver.onNext(GoodbyeResponse.newBuilder().setFarewell(farewell).build()); responseObserver.onCompleted(); } }
@java.lang.Override protected GreetingServiceBlockingStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new GreetingServiceBlockingStub(channel, callOptions); }
/** */ public com.example.grpc.HelloResponse greeting(com.example.grpc.HelloRequest request) { return blockingUnaryCall( getChannel(), getGreetingMethodHelper(), getCallOptions(), request); } }
/** */ public com.example.grpc.HelloResponse secondGreeting(com.example.grpc.HelloRequest request) { return blockingUnaryCall( getChannel(), getSecondGreetingMethodHelper(), getCallOptions(), request); } }
/** */ public com.example.grpc.HelloResponse secondGreeting(com.example.grpc.HelloRequest request) { return blockingUnaryCall( getChannel(), getSecondGreetingMethodHelper(), getCallOptions(), request); } }
/** */ public com.example.grpc.HelloResponse greeting(com.example.grpc.HelloRequest request) { return blockingUnaryCall( getChannel(), getGreetingMethodHelper(), getCallOptions(), request); }
/** * Creates a new blocking-style stub that supports unary and streaming output calls on the service */ public static GreetingServiceBlockingStub newBlockingStub( io.grpc.Channel channel) { return new GreetingServiceBlockingStub(channel); }
@java.lang.Override protected GreetingServiceBlockingStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { return new GreetingServiceBlockingStub(channel, callOptions); }
/** */ public com.example.grpc.HelloResponse greeting(com.example.grpc.HelloRequest request) { return blockingUnaryCall( getChannel(), getGreetingMethodHelper(), getCallOptions(), request); }