- 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.
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);
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)));
}
}- 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.
Maven Coordinates
The Getting Started page describes how you should declare dependency management for Helidon applications. Then declare the following dependency in your project:
<dependency>
<groupId>io.helidon.grpc</groupId>
<artifactId>helidon-grpc-server</artifactId>
</dependency>- Dependency on gRPC Server.