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(); } }
static public void main(String[] args) throws IOException, InterruptedException { JwtServerInterceptor jwtInterceptor = new JwtServerInterceptor(Constant.JWT_SECRET); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new JwtClientInterceptor()) .intercept(new TraceIdClientInterceptor()) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel); Server goodbyeServer = ServerBuilder.forPort(9090) .addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub), jwtInterceptor, new TraceIdServerInterceptor())) .build(); goodbyeServer.start(); System.out.println("Server started!"); goodbyeServer.awaitTermination(); }
static public void main(String[] args) throws IOException, InterruptedException { Brave brave = Constant.brave("goodbye-service"); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new BraveGrpcClientInterceptor(brave)) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel); Server goodbyeServer = ServerBuilder.forPort(9090) .addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub), new BraveGrpcServerInterceptor(brave), MonitoringServerInterceptor.create(Configuration.allMetrics()))) .build(); goodbyeServer.start(); PrometheusServer prometheusServer = new PrometheusServer(CollectorRegistry.defaultRegistry, 8081); prometheusServer.start(); System.out.println("Server started!"); goodbyeServer.awaitTermination(); prometheusServer.shutdown(); }
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); }); }