@Override public void secondGreeting(HelloRequest request, StreamObserver<HelloResponse> responseObserver) { GoodbyeResponse goodbye = goodbyeStub.goodbye(GoodbyeRequest.newBuilder().setName(request.getName()).build()); System.out.println("Say Goodbye! " + goodbye); greeting(request, responseObserver); } }
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) { ManagedChannel goodbyeChannel = ManagedChannelBuilder.forAddress("localhost", 9090) .usePlaintext(true) .intercept(new BraveGrpcClientInterceptor(Constant.brave("client-example"))) .intercept(MonitoringClientInterceptor.create(Configuration.allMetrics())) .build(); for (int i = 0; i < 100; i++) { GoodbyeServiceGrpc.GoodbyeServiceBlockingStub stub = GoodbyeServiceGrpc.newBlockingStub(goodbyeChannel); GoodbyeResponse goodbye = stub.goodbye(GoodbyeRequest.newBuilder().setName("Ray").build()); System.out.println(goodbye); } goodbyeChannel.shutdownNow(); } }