Skip to main content

Auto Configuration

Dependencies

implementation("io.github.danielliu1123:grpc-server-boot-starter")

Register Services

After adding the dependencies, the application will start a gRPC server at 9090, and it will automatically scan and register gRPC services. You only need to add @Component based annotation to your service implementations.

@Component
public class SimpleServiceImpl extends SimpleServiceGrpc.SimpleServiceImplBase {
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
var response = SimpleResponse.newBuilder().setResponseMessage("Hello " + request.getRequestMessage()).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
info

The framework provides a @GrpcService annotation to better distinguish bean types. But it is not necessary, you can use Spring's built-in @Component/@Service/@Controller instead.

In-process Server

gRPC server supports in-process transport, which is useful for testing scenarios.

grpc:
server:
in-process:
name: whatever

Build-in Services

io.grpc:grpc-services provides a series of built-in services.

Health

Health service is enabled by default.

Use the following configuration to disable it:

grpc:
server:
health:
enabled: false

You can customize the health check logic by implementing the HealthChecker interface.

There are two build-in HealthChecker implementations, DataSourceHealthChecker and RedisHealthChecker.

DataSourceHealthChecker is enabled by default when the spring-boot-starter-jdbc is on the classpath.

RedisHealthChecker is enabled by default when the spring-boot-starter-data-redis is on the classpath.

Use the following configuration to disable them:

grpc:
server:
health:
datasource:
enabled: false
redis:
enabled: false

Reflection

Reflection is disabled by default, it's often used in development and debugging scenarios.

Use the following configuration to enable it:

grpc:
server:
reflection:
enabled: true

Channelz

Channelz is disabled by default.

Use the following configuration to enable it:

grpc:
server:
channelz:
enabled: true

Configurations

Full configuration is available in the GrpcServerProperties.