Generating code for services?
I am using Protox for a gRPC client, which needs service definitions. Right now I'm manually creating structs like:
%{
request_type: Echo.EchoRequest,
request_stream?: false,
response_type: Echo.EchoReply,
response_stream?: false,
service: "SayHello",
service_module: "echo"
}
for
syntax = "proto3";
package echo;
service EchoServer {
rpc SayHello (EchoRequest) returns (EchoReply) {}
}
It would be great if Protox could handle the service definitions as well. What are your thoughts on this?
Hello,
Good question! TBH, I'm not clear on how protox could support gRPC. For instance, I thought it would required to have some kind of HTTP/2 server. But, it seems that in your case, you juste need to generate some data structures from a service definition. Is that right?
Yes, to support both client and server gRPC like https://github.com/elixir-grpc/grpc does an HTTP2 server would be needed (perhaps in the future it could work with Bandit. However, I'm only looking for a client right now (based on Mint), and for that a data structure for the service definition is sufficient.
OK, it's clearer, thanks! However, I can't find the specification of this structure on https://grpc.io/docs or how a service is effectively described in protobuf. Can you point me to some documentation? Furthermore, how do you serialize it? I mean, as it's not a protobuf struct, what do you send as HTTP payload? JSON?
Also, I take the opportunity of this discussion to ask a naive question: I'm obviously happy that you are using protox 🙂, but wouldn't it be easier to use elixir-grpc? As it's difficult to have feedback for open-source software, I'll be glad to know the features of protox that made you choose it 🙂.
There is some documentation here and here.
wouldn't it be easier to use elixir-grpc?
That library is unfortunately [no longer maintained])(https://github.com/elixir-grpc/grpc/graphs/contributors), and I would rather have client based on Mint.
how do you serialize it? I mean, as it's not a protobuf struct, what do you send as HTTP payload? JSON?
You don't serialize the service, it is only used to know what type of data to send where. Then you send the serialized protocol buffer over the gRPC protocol (based on HTTP2).
I have a working version, based on the client from Spear, at https://github.com/hkrutzer/grpc_client.
Here you can see an example of how to perform a request. The GrpcClient.Rpc part is what I'm looking for; right now I'm typing it out manually.
OK, thanks for your detailed answer, it's much clearer now! I hope I'll be able to take a look at all this in a few days, but the next 2 months will be pretty busy, so no promise 😅!
There is some documentation here and here.
wouldn't it be easier to use elixir-grpc?
That library is unfortunately [no longer maintained])(https://github.com/elixir-grpc/grpc/graphs/contributors), and I would rather have client based on Mint.
how do you serialize it? I mean, as it's not a protobuf struct, what do you send as HTTP payload? JSON?
You don't serialize the service, it is only used to know what type of data to send where. Then you send the serialized protocol buffer over the gRPC protocol (based on HTTP2).
I have a working version, based on the client from Spear, at https://github.com/hkrutzer/grpc_client.
Here you can see an example of how to perform a request. The
GrpcClient.Rpcpart is what I'm looking for; right now I'm typing it out manually.
Good news, the library has a new maintainer now. :)
As there is an alternative, I'll close this issue, but I'll definitely keep this on my TODO list 😉