in plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterClient.java [32:78]
public static void main(String[] args) {
// Boot pekko
ActorSystem sys = ActorSystem.create("LoggingErrorHandlingGreeterClient");
// Take details how to connect to the service from the config.
GrpcClientSettings clientSettings =
GrpcClientSettings.connectToServiceAt("127.0.0.1", 8082, sys).withTls(false);
// Create a client-side stub for the service
GreeterServiceClient client = GreeterServiceClient.create(clientSettings, sys);
try {
HelloRequest Martin = HelloRequest.newBuilder().setName("Martin").build();
CompletionStage<HelloReply> successful = client.sayHello(Martin);
successful.toCompletableFuture().get(10, TimeUnit.SECONDS);
sys.log().info("Call succeeded");
HelloRequest martin = HelloRequest.newBuilder().setName("martin").build();
CompletionStage<HelloReply> failedBecauseLowercase = client.sayHello(martin);
failedBecauseLowercase
.handle(
(response, exception) -> {
if (exception != null) {
sys.log().info("Call with lowercase name failed");
}
return response;
})
.toCompletableFuture()
.get(10, TimeUnit.SECONDS);
HelloRequest empty = HelloRequest.newBuilder().setName("").build();
CompletionStage<HelloReply> failedBecauseEmpty = client.sayHello(empty);
failedBecauseEmpty
.handle(
(response, exception) -> {
if (exception != null) {
sys.log().info("Call with empty name failed");
}
return response;
})
.toCompletableFuture()
.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
sys.terminate();
}