grpc

144 views
Skip to first unread message

Lu Roy

unread,
Mar 29, 2016, 11:21:32 PM3/29/16
to grp...@googlegroups.com

hi, there

i'm currently learning grpc and it is really easy to use. I'm using maven plugin to generate java code. So far, it works well. 


But, the grpc client must specify the server host and port, if the server was down, the client can't get service any more. How can we solve this in a distributed system? If one server was down, the client can automatically find another valid server and do the rpc request. Is there a location discovery service to help? Or we can use nginx to do the proxy?


Another question, i found the has* method was very useful in proto2. But in proto3, there is no has* method in generated java file any more. why?


for instance, like the proto below,


message HelloRequest {
     int32 num = 1;
}

in proto2, the generated java file has the "hasNum()" method to know if the client has set the num or not. Although it has a default value for int which is 0, but sometime we want to know whether the client has specified the field or not. 


Can we still have this function in proto3?


sincerely, 

Roy Lu



Eric Anderson

unread,
Mar 30, 2016, 11:59:07 AM3/30/16
to Lu Roy, grp...@googlegroups.com
On Tue, Mar 29, 2016 at 8:21 PM, Lu Roy <lifeliv...@hotmail.com> wrote:

But, the grpc client must specify the server host and port, if the server was down, the client can't get service any more. How can we solve this in a distributed system? If one server was down, the client can automatically find another valid server and do the rpc request. Is there a location discovery service to help?

We call service discovery "naming," and it in an important part of gRPC. Instead of using forAddress(), you can use forTarget(). The only built-in name resolver in Java currently is DNS, but you can use NameResolverRegistry.getDefaultRegistry().register() to add your own. The resolved names are then passed to a load balancer module. The default just uses the first working address, so if the host goes down it will end up trying another.

Or we can use nginx to do the proxy?

Mostly. nginx does not yet support HTTP/2 to the backend, so you can't use it yet. But you can use something similar like nghttp2.

Another question, i found the has* method was very useful in proto2. But in proto3, there is no has* method in generated java file any more. why?

This was removed in proto3 to more closely align proto with how primitives work in many languages and to simplify implementation. Note that I said "primitives;" those methods still exist for messages.

There's now standard "boxing" types that you can use when you need presence information for primitives.
Reply all
Reply to author
Forward
0 new messages