Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Last active October 9, 2021 17:55
Show Gist options
  • Save GaetanoPiazzolla/96ca06eba059df295811680cb1ec5d6a to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/96ca06eba059df295811680cb1ec5d6a to your computer and use it in GitHub Desktop.
GrpcClientService
import gae.piaz.grpc.lib.HelloReply;
import gae.piaz.grpc.lib.HelloRequest;
import gae.piaz.grpc.lib.SimpleGrpc;
import org.springframework.stereotype.Service;
import io.grpc.StatusRuntimeException;
import net.devh.boot.grpc.client.inject.GrpcClient;
@Service
public class GrpcClientService {
@GrpcClient("grpc-server")
private SimpleGrpc.SimpleBlockingStub simpleStub;
public String sendMessage(final String name) {
try {
final HelloReply response = this.simpleStub.sayHello(HelloRequest.newBuilder().setName(name).build());
return response.getMessage();
} catch (final StatusRuntimeException e) {
return "FAILED with " + e.getStatus().getCode().name();
}
}
}
@GaetanoPiazzolla
Copy link
Author

GaetanoPiazzolla commented Oct 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment