Spring / Spring gRPC Interview Questions
What does the @GrpcService annotation do?
@GrpcService marks a class - one that extends a generated *ImplBase base class from your .proto definition - as both a regular Spring-managed bean and a gRPC service that should be registered on the embedded gRPC server.
@GrpcService public class GreetingService extends GreeterGrpc.GreeterImplBase { @Override public void sayHello(HelloRequest req, StreamObserver<HelloReply> obs) { HelloReply reply = HelloReply.newBuilder() .setMessage("Hello " + req.getName()) .build(); obs.onNext(reply); obs.onCompleted(); } }
Conceptually it plays the same role for gRPC that @RestController plays for HTTP endpoints: it tells the framework 'this class implements a service contract and should be exposed automatically,' while still letting the class participate fully in Spring's dependency injection.
More Related questions...