- gRPC Server Introduction
Helidon gRPC Server provides a framework for creating gRPC applications.
Experimental
The Helidon gRPC feature is currently experimental and the APIs are subject to changes until gRPC support is stabilized.
Maven Coordinates
To enable gRPC add the following dependency to your project’s pom.xml (see Managing Dependencies).
<dependency>
<groupId>io.helidon.grpc</groupId>
<artifactId>helidon-grpc-server</artifactId>
</dependency>content_copy
Quick Start
Here is the code for a minimalist gRPC application that runs on a default port (1408):
public static void main(String[] args) throws Exception {
GrpcServer grpcServer = GrpcServer
.create(GrpcRouting.builder()
.register(new HelloService())
.build())
.start()
.toCompletableFuture()
.get(10, TimeUnit.SECONDS); // Implement the simplest possible gRPC service.
System.out.println("gRPC Server started at: http://localhost:" + grpcServer.port());
}
static class HelloService implements GrpcService {
@Override
public void update(ServiceDescriptor.Rules rules) {
rules.unary("SayHello", ((request, responseObserver) -> complete(responseObserver, "Hello " + request)));
}
}content_copy
- Register gRPC service.
- Start the server.
- Wait for the server to start while throwing possible errors as exceptions.
- The server is bound to a default port (1408).
- Implement the simplest possible gRPC service.
- Add unary method
HelloService/SayHelloto the service definition.
The example above deploys a very simple service to the gRPC server that by default uses Java serialization to marshall requests and responses. We will look into deployment of "standard" gRPC services that use Protobuf for request and response marshalling, as well as how you can configure custom marshallers, later in this document.