9
votes

For a project I'd like to set up a small microservice scenario using Spring Boot with an API gateway exposing REST and GraphQL to the clients, a Eureka service registry and three services. I want all services behind the API gateway to talk gRPC because of performance reasons, but at the same time still expose an additional REST API. Is there a clean way to implement both types of interfaces on top of the same business logic? And how would the gateway proxy the clients' HTTP requests to gRPC ones?

1

1 Answers

2
votes

You can look into LogNet grpc-spring-boot-starter to see how to integrate gRPC into Spring Boot, it also has a section about Eureka.

As per Eureka example, make sure you don't create new connection over gRPC for each call.

Depending on the implementation of the API gateway, it should also talk to Eureka, and access downstream services by logical names via gRPC.

As per second part, simply implement your business logic in Spring Services, and forward calls to them from the transport related abstractions (Controllers and gRPC services).

Optionally, you can go even further, and define all messages in Protobuf only. And then register Spring's Protobuf Converter for HTTP.