0
votes

I am trying to write services that use both gRPC and REST. The implementing technologies are Java, Spring Boot and gRPC. An example usage scenario follows:

Usage diagram

The intent is that there are external clients that may interact with the application via REST endpoints and/or by making gRPC calls. Internally, there are "gateway" services that provide the external interfaces and take care of transporting/routing requests and responses between the external clients and the "domain" services, that do the actual work. The internal services will communicate via gRPC.

The external client has no knowledge of how things are handled internally and the domain services have no external interfaces.

I have been able to get a basic request/response pattern to work from end-to-end, but am not sure how to implement patterns that involve streaming (in either direction). Actually, that's not entirely true - I have been able to get the basic examples provided on the gRPC site (https://grpc.io/) to work.

Here is an example of what I'm trying to do, that I can't seem to figure out how to make work:

The "domain" service has the ability to return a collection of objects (i.e. the stream source) to a requestor. The domain uses gRPC logic to provide these objects to the calling client (the "gateway" in this case). An external client makes a REST call to the gateway service to request the object collection that the domain service provides.

As far as I can tell, the domain and gateway talk to each other just fine, but there is a problem when it tries to send the information back to the external client. For specific details about the code and the errors I've been running into, please see related issue Problem returning stream of responses from gRPC service to RESTful client.

One question that comes to mind is: can REST be used to handle streaming of information (in either direction)? If it cannot, what options do I have, if any? If it can, how do I go about it?

UPDATE:

I have made updates to the referenced companion SO posting above.

1
perhaps you'll find some hint here [baeldung.com/spring-rest-api-with-protocol-buffers], there's a ProtobufHttpMessageConverter from com.google.protobuf.protobuf-javaMarc Stroebel
@Marc Yes, I saw the article by Baeldung and was able to apply some of his techniques. It works when I have a simple request/response, but I'm having a problem with trying to use the gRPC "stream" concept to stream a collection of responses back from the server.Joseph Gagnon
@Joseph Did you got any solution for this?Thinker

1 Answers

0
votes

you could try StreamingResponseBody (https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBody.html), it allows writing to the output stream without blocking the main thread.