Add reflection service to grpc server

User can now inspect service definitions (e.g. with grpcurl).
This commit is contained in:
Dave Syer
2021-10-11 15:42:15 +01:00
parent 7fc755e157
commit 78f485d7c0
2 changed files with 14 additions and 4 deletions

View File

@@ -31,6 +31,11 @@
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-services</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>

View File

@@ -19,13 +19,15 @@ package org.springframework.cloud.function.grpc;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.SmartLifecycle;
import org.springframework.util.ClassUtils;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.SmartLifecycle;
import io.grpc.protobuf.services.ProtoReflectionService;
/**
*
@@ -58,6 +60,9 @@ class GrpcServer implements SmartLifecycle {
BindableService bindableService = this.grpcMessageServices[i];
serverBuilder.addService(bindableService);
}
if (ClassUtils.isPresent("io.grpc.protobuf.services.ProtoReflectionService", null)) {
serverBuilder.addService(ProtoReflectionService.newInstance());
}
this.server = serverBuilder.build();
logger.info("Starting gRPC server");