Reputation: 23
I am pretty new to gRPC. I am thinking of using gRPC(Java) to do inter node(server) communication in my use case:
for example, I have node A, B, C. I will need to have gRPC serverA, serverB, serverC start first, and for each server say A, I need client to connect to B and C. and in addition to communication part, app (say in node A)logic would be able to send out msg to other nodes(say B and C) via corresponding clients(to server B and C) if needed;and of course app logic would be notified when requests coming from B and C(because itself is a server).
I've been searching online for days and have gone through grpc/grpc-java related material and code example. however, i find there's not that much code example to show what is best practice and pattern to leverage gRPC...i'd really like to hear whatever suggestion you may have...
thanks in advance!
Upvotes: 2
Views: 3020
Reputation: 26464
Calling server.awaitTermination()
in your main()
is not required. The examples do so because grpc-java uses daemon threads by default. Thus, in the examples the only non-daemon thread is the main thread, and you need at least one non-daemon thread to keep the JVM running. See the documentation for java.lang.Thread.
awaitTermination()
is not a serve_forever()
method that processes new requests; awaitTermination()
simply blocks the current thread until the grpc server has terminated. Processing happens on other threads.
Upvotes: 2