Spring / Spring gRPC Interview Questions
What is a.proto file and what is it used for?
A .proto file is a Protocol Buffers interface definition file. It declares two things: message types, which describe the shape of data exchanged, and service definitions, which list the RPC methods a service exposes along with each method's request and response message types.
syntax = "proto3"; message HelloRequest { string name = 1; } message HelloReply { string message = 1; } service Greeter { rpc SayHello (HelloRequest) returns (HelloReply); }
The protoc compiler (or a build-tool plugin) reads this file and generates language-specific code - for Java, that means message builder classes and a service base class/stub pair. Because the .proto file is the single authoritative contract, it is typically kept in a shared location or repository so client and server teams generate compatible code from the exact same definition.
More Related questions...