For us, the decision comes down to having existing protocol buffers or not.
Often times, we'll have a message defined for other purposes, e.x.:
message Contact {
repeated Name name = 1;
// etc..
}
And since we want RPC to be orthogonal from the storage models, we'll
create wrappers:
message GetContactRequest {
string id = 1;
}
message GetContactResponse {
Contact contact = 1;
// other metadata irrelevant to a "contact"
}
message PutContactRequest {
string id = 1;
Contact contact = 2;
}
// etc.
Since we use protocol buffer throughout our stack (storage, task queueing,
etc.), composing them into Request/Response wrappers make sense for us. If
you're just using protocol buffers to drive logic that doesn't otherwise
care about protocol buffers, it seems like the former is nicer.
Michael
On Thursday, March 9, 2017 at 2:12:41 AM UTC-7, Jorg Heymans wrote:
>
> Hi,
>
> I am wondering what style people are using to define their grpc services.
> For example, a service def could be written something like this, in its
> most simple form:
>
> syntax = "proto3";
>
> package test;
>
> message Ping {
> string theMessage = 1;
> }
>
> message Pong {
> string theResponse = 1;
> }
>
> service MyService {
> rpc SaySomething (Ping) returns (Pong);
> }
>
> Or, I have also seen this style where the payloads are encapsulated in
> separate request and response objects (more like how you would do it in
> schema perhaps)
>
> syntax = "proto3";
>
> package test;
>
> message Ping {
> string theMessage = 1;
> }
>
> message PingRequest {
> Ping request = 1;
> }
>
> message Pong {
> string theResponse = 1;
> }
>
> message PongResponse {
> Pong response = 1;
> }
>
> service MyService {
> rpc SaySomething (PingRequest) returns (PongResponse);
> }
>
> I find that - at least in java - this definition generates a slightly
> easier to discover code syntax from the ide, but is it worthwhile to
> introduce the indirection and extra payload bytes just for this?
>
> Would be nice to hear from long-time grpc users which style they prefer
> and why :-)
>
> Thanks,
> Jorg
>
--
*CONFIDENTIALITY NOTICE: This email message, and any documents, files or
previous e-mail messages attached to it is for the sole use of the intended
recipient(s) and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited. If you
are not the intended recipient, please contact the sender by reply email
and destroy all copies of the original message.*
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/ec1f5c55-8ceb-4245-b4d2-ba8b1e29c0a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.