use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.
the class BaseITTracingServerInterceptor method bodyTaggingExample.
/**
* This shows that a {@link ServerInterceptor} can see the server server span when processing the
* request and response.
*/
@Test
public void bodyTaggingExample() throws IOException {
SpanCustomizer customizer = CurrentSpanCustomizer.create(tracing);
AtomicInteger sends = new AtomicInteger();
AtomicInteger recvs = new AtomicInteger();
init(new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
call = new SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
public void sendMessage(RespT message) {
delegate().sendMessage(message);
customizer.tag("grpc.message_send." + sends.getAndIncrement(), message.toString());
}
};
return new SimpleForwardingServerCallListener<ReqT>(next.startCall(call, headers)) {
@Override
public void onMessage(ReqT message) {
customizer.tag("grpc.message_recv." + recvs.getAndIncrement(), message.toString());
delegate().onMessage(message);
}
};
}
});
GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
assertThat(testSpanHandler.takeRemoteSpan(Span.Kind.SERVER).tags()).containsKeys("grpc.message_recv.0", "grpc.message_send.0");
Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST);
assertThat(replies).toIterable().hasSize(10);
// Intentionally verbose here to show that only one recv and 10 replies
assertThat(testSpanHandler.takeRemoteSpan(Span.Kind.SERVER).tags()).containsKeys("grpc.message_recv.1", "grpc.message_send.1", "grpc.message_send.2", "grpc.message_send.3", "grpc.message_send.4", "grpc.message_send.5", "grpc.message_send.6", "grpc.message_send.7", "grpc.message_send.8", "grpc.message_send.9", "grpc.message_send.10");
}
use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.
the class GreeterImpl method sayHello.
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
TraceContext currentTraceContext = tracing != null ? tracing.currentTraceContext().get() : null;
if (req.getName().equals("bad")) {
responseObserver.onError(new IllegalArgumentException("bad"));
return;
}
if (req.getName().equals("testerror")) {
throw new RuntimeException("testerror");
}
String message = currentTraceContext != null ? currentTraceContext.traceIdString() : "";
HelloReply reply = HelloReply.newBuilder().setMessage(message).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.
the class ITTracingClientInterceptor method clientParserTestStreamingResponse.
@Test
public void clientParserTestStreamingResponse() throws Exception {
closeClient(client);
tracing = tracing.toBuilder().clientParser(new GrpcClientParser() {
int receiveCount = 0;
@Override
protected <M> void onMessageReceived(M message, SpanCustomizer span) {
span.tag("grpc.message_received." + receiveCount++, message.toString());
}
}).build();
client = newClient();
Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HelloRequest.newBuilder().setName("this is dog").build());
assertThat(replies).hasSize(10);
Span span = spans.take();
// all response messages are tagged to the same span
assertThat(span.tags()).hasSize(10);
}
use of io.grpc.examples.helloworld.HelloReply in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
VertxServer server = VertxServerBuilder.forPort(vertx, 8080).addService(new GreeterGrpc.GreeterVertxImplBase() {
@Override
public void sayHello(HelloRequest request, Future<HelloReply> future) {
System.out.println("Hello " + request.getName());
future.complete(HelloReply.newBuilder().setMessage(request.getName()).build());
}
}).useSsl(options -> options.setSsl(true).setUseAlpn(true).setKeyStoreOptions(new JksOptions().setPath("tls/server-keystore.jks").setPassword("wibble"))).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.
the class SafeMethodCachingInterceptorTest method unsafeCallsAreNotCached.
@Test
public void unsafeCallsAreNotCached() {
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse);
HelloReply reply1 = stub.sayHello(message);
HelloReply reply2 = stub.sayHello(message);
assertNotEquals(reply1, reply2);
}
Aggregations