Reputation: 35
I am trying to learn to use grpc
, and after reading a while in the grpc website I have some questions.
Let's say I have machine A with a grpc server written in python
. I want to run on machine B a grpc client in node.js
to communicate with the server on machine A.
The first question is, does the server and client need to share the same .proto
file? Also, can I write the client part without knowing the server source code? What are my guidelines doing so?
In general, I didn't really get how can you write a client for a remote server or vice versa, and I would really appreciate if someone could give me a good explanation on the process.
All examples in the grpc
website are with same language for server and client, and runs from the same machine and even the same folder which makes it harder for me to understand how it works remotely.
Thank you for any explanation provided.
Upvotes: 1
Views: 1100
Reputation: 18430
The R
in gRPC stands for Remote so calling code on another machine is the main purpose.
Using the .proto
file, you can generate the server and client code in any language and run it on any machine.
The file should be shared between the client and the server which can be written in different languages. Backward-compatible changes are supported e.g. adding a new optional field in the servee .proto
does not require updating the older client .proto
file
.proto
file defines both the message format and the RPC service to expose. The service fullname will be part of the URL when calling it from a remote machine.
Upvotes: 2