CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-grpc--grpc-services

gRPC service utilities providing health checking, server reflection, channelz observability, and binary logging capabilities

Pending
Overview
Eval results
Files

server-reflection.mddocs/

Server Reflection Services

Protocol buffer service reflection enabling dynamic service discovery and debugging tools. Server reflection allows clients to discover available services and their method signatures at runtime.

Capabilities

ProtoReflectionServiceV1

Current implementation of the server reflection service using the v1 protocol.

/**
 * Provides reflection service for Protobuf services using v1 protocol.
 * Enables clients to discover available services and method signatures.
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
public final class ProtoReflectionServiceV1 {
  
  /**
   * Creates an instance of ProtoReflectionServiceV1
   * @return BindableService that can be added to a gRPC server
   */
  public static BindableService newInstance();
  
  // Note: serverReflectionInfo() is an internal implementation method
  // Users don't call this directly - it's automatically invoked by gRPC framework
}

Usage Examples:

import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;

// Add reflection service to server
Server server = ServerBuilder.forPort(8080)
    .addService(ProtoReflectionServiceV1.newInstance())
    .addService(new MyBusinessService())
    .addService(new AnotherService())
    .build();

server.start();

ProtoReflectionService (Deprecated)

Legacy implementation using the deprecated v1alpha protocol.

/**
 * Provides reflection service for Protobuf services using deprecated v1alpha protocol.
 * @deprecated Use ProtoReflectionServiceV1 instead
 */
@Deprecated
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
public final class ProtoReflectionService {
  
  /**
   * Creates a new instance (deprecated, use ProtoReflectionServiceV1 instead)
   * @return BindableService that can be added to a gRPC server
   * @deprecated Use ProtoReflectionServiceV1.newInstance() instead
   */
  @Deprecated
  public static BindableService newInstance();
  
  /**
   * Binds the service
   * @return ServerServiceDefinition for the reflection service
   */
  public ServerServiceDefinition bindService();
}

Client Usage with Reflection

Server reflection enables various debugging and development tools:

Using grpcurl with Reflection

# List all services available on the server
grpcurl -plaintext localhost:8080 list

# Get details about a specific service
grpcurl -plaintext localhost:8080 describe com.example.UserService

# Get details about a specific method
grpcurl -plaintext localhost:8080 describe com.example.UserService.GetUser

Programmatic Client Discovery

import io.grpc.reflection.v1.ServerReflectionGrpc;
import io.grpc.reflection.v1.ServerReflectionRequest;
import io.grpc.reflection.v1.ServerReflectionResponse;

// Create reflection client
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
    .usePlaintext()
    .build();

ServerReflectionGrpc.ServerReflectionStub reflectionStub = 
    ServerReflectionGrpc.newStub(channel);

// Stream observer to handle responses
StreamObserver<ServerReflectionResponse> responseObserver = 
    new StreamObserver<ServerReflectionResponse>() {
        @Override
        public void onNext(ServerReflectionResponse response) {
            // Handle reflection response
            if (response.hasListServicesResponse()) {
                response.getListServicesResponse().getServiceList()
                    .forEach(service -> 
                        System.out.println("Service: " + service.getName())
                    );
            }
        }
        
        @Override
        public void onError(Throwable t) {
            System.err.println("Reflection error: " + t.getMessage());
        }
        
        @Override
        public void onCompleted() {
            System.out.println("Reflection completed");
        }
    };

// Request stream to send reflection requests
StreamObserver<ServerReflectionRequest> requestObserver = 
    reflectionStub.serverReflectionInfo(responseObserver);

// List all services
ServerReflectionRequest listServicesRequest = ServerReflectionRequest.newBuilder()
    .setListServices("")
    .build();
    
requestObserver.onNext(listServicesRequest);
requestObserver.onCompleted();

Integration with Development Tools

Server reflection enables integration with various gRPC development and debugging tools:

import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.protobuf.services.HealthStatusManager;

public class DevelopmentServer {
    
    public static void main(String[] args) throws Exception {
        HealthStatusManager healthManager = new HealthStatusManager();
        
        // Development server with reflection and health checking
        Server server = ServerBuilder.forPort(8080)
            // Add reflection for development tools
            .addService(ProtoReflectionServiceV1.newInstance())
            
            // Add health checking for load balancer integration
            .addService(healthManager.getHealthService())
            
            // Add business services
            .addService(new UserService())
            .addService(new OrderService())
            .build();
        
        server.start();
        healthManager.setStatus("", ServingStatus.SERVING);
        
        System.out.println("Development server started on port 8080");
        System.out.println("Use grpcurl to explore services:");
        System.out.println("  grpcurl -plaintext localhost:8080 list");
        
        server.awaitTermination();
    }
}

Security Considerations

Server reflection exposes service information and should be used carefully in production:

// Only enable reflection in development/staging environments
String environment = System.getProperty("environment", "development");

ServerBuilder<?> serverBuilder = ServerBuilder.forPort(8080);

if ("development".equals(environment) || "staging".equals(environment)) {
    // Enable reflection for development tools
    serverBuilder.addService(ProtoReflectionServiceV1.newInstance());
    System.out.println("Server reflection enabled for " + environment);
} else {
    System.out.println("Server reflection disabled in production");
}

Server server = serverBuilder
    .addService(new ProductionService())
    .build();

Install with Tessl CLI

npx tessl i tessl/maven-io-grpc--grpc-services

docs

admin-services.md

binary-logging.md

channelz.md

health-checking.md

index.md

load-balancing.md

metrics.md

server-reflection.md

tile.json