A gRPC proxy implementation that allows proxying gRPC requests through HTTP/JSON rules using Spring Cloud Gateway.
This project provides a proxy solution for gRPC services that:
- Converts gRPC requests/responses to JSON format
- Uses Spring Cloud Gateway for routing and filtering
- Supports dynamic service discovery through gRPC reflection
- Allows configuration via HTTP routing rules
reflection-extension
: gRPC reflection support for service discoveryspring-cloud-gateway
: Core proxy implementation using Spring Cloud Gatewayexamples
:example-server
: Sample gRPC server implementationexample-spring-cloud-gateway
: Example proxy configuration
- Protocol Translation: Seamlessly converts between gRPC and JSON formats
- HTTP-based Routing: Define routing rules using familiar HTTP patterns
- Service Discovery: Automatic service and method discovery via gRPC reflection
See the examples directory for sample implementations showing how to:
- Set up a gRPC server
- Configure the proxy using Spring Cloud Gateway
- Define routing rules for JSON/gRPC translation
Add the JitPack repository to your build file:
repositories {
maven { url "https://jitpack.io" }
}
implementation 'com.github.protobuf-x.grpc-proxy:reflection-extension:${release-version}'
implementation 'com.github.protobuf-x.grpc-proxy:spring-cloud-gateway:${release-version}'
- Your gRPC server must have reflection service enabled
- Server must be accessible from the proxy
- Protocol buffers must be properly configured in your project
- Spring Cloud Gateway dependencies must be properly configured
- Your application must be configured as a Spring Boot application
Server server = ServerBuilder.forPort(9090)
.addService(new YourServiceImpl())
.addService(ReflectionExtensionService.newInstance()) // Add this line
.build();
You can configure the gateway either through Java configuration or YAML configuration.
@SpringBootApplication
public class ExampleGateway {
@Bean
RouteLocator routeLocator(RouteLocatorBuilder builder, GatewayFilter httpRuleJsonToGrpcGatewayFilter) {
return builder.routes()
.route("json-to-grpc", r -> r
.path("/example.echo.v1.EchoService/**")
.filters(f -> f.filter(httpRuleJsonToGrpcGatewayFilter))
.uri("http://localhost:6565")
).build();
}
@Bean
GatewayFilter httpRuleJsonToGrpcGatewayFilter(ChannelRepository channelRepository,
ProtobufRepository protobufRepository) {
return new HttpRuleJsonToGrpcGatewayFilterFactory(channelRepository, protobufRepository)
.apply(new HttpRuleJsonToGrpcGatewayFilterFactory.Config());
}
@Bean
ProtobufRepository protoRepository(ChannelRepository channelRepository) {
return new CacheableServerProtobufRepository(channelRepository, 60);
}
@Bean
ChannelRepository channelRepository() {
return new InmemoryChannelRepository();
}
}
For more detailed configuration examples, please refer to the examples directory.
This project is licensed under the MIT License