Anyone having any examples or thoughts using gRPC together with Spring Boot?
If you need a gRPC client library, i.e. consume stubs, check out my library https://github.com/sfcodes/grpc-client-spring-boot
This library will automatically scan your classpath, find all gRPC stub classes, instantiate them, and register them as beans with the ApplicationContext; allowing you to easily @Autowire
and inject them just like you would any other Spring bean. For example:
@RestController
public class GreeterController {
@Autowired // <===== gRPC stub is autowired!
private GreeterGrpc.GreeterBlockingStub greeterStub;
@RequestMapping(value = "/sayhello")
public String sayHello(@RequestParam String name) {
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloReply reply = greeterStub.sayHello(request);
return reply.getMessage();
}
}
For gRPC server library, I'd also recommend LogNet/grpc-spring-boot-starter
.