I am exploring on grpc
My sample application fetches few records from Database + reads a file from S3(very small file) and returns the combined result.
Since the file size is very less, i am not using streams.
So, the service layer of my application will return a CompletableFuture
CompletableFuture<Book> getContent(String bookId);
My Grpc ServiceBaseImpl will have the below code.
public void getBook(GetBookrequest request, StreamObserver<Book> responseObserver){
CompletableFuture<Book> bookContentFuture = bookService.getContent(request.getBookId());
Book book = bookContentFuture.get() ; // blocking
responseObserver.onNext(book);
responseObserver.onCompleted();
}
Here i am making a blocking get call and waiting for the result before send the response back.
In Rest Application , i can have a controller which can return the CompletableFuture<Book>
Is it possible to return a Future in GRPC .
I don`t find any future type in protobuf , it means its okay to block before responding?
generally not recommended to block and wait for CompletableFuture .
if you have a small file size and dont want to use streaming, you can theoretically blcok and wait for CompletableFuture before sending the response back.
you can still return CompletableFuture from the service method.
something like this