4
votes

Let's say I have a gRPC Java service that is hosting a Server.

So when a client wants to call this service, they use:

ManagedChannel channel = ManagedChannelBuilder
        .forAddress(grpcHost, grpcPort)
        .usePlaintext(true)
        .build();

No problem.

Now what if I want to call my service from the same JVM? Is this even possible? Or perhaps this is completely invalid?

1
It is possible, it works fine. You might be interested in InProcessServer and InProcessChanell for this case. github.com/grpc/grpc-java/blob/master/testing/src/main/java/io/…Grzegorz Żur

1 Answers

4
votes

You are free to use plain ManagedChannelBuilder to connect to the same JVM. It will work just like normal.

If you want to optimize the case because it can happen frequently and are in the same ClassLoader (so it wouldn't work between Servlets, for example), you can use the in-process transport. The in-process transport has relatively low overhead and can even avoid serializing/deserializing the Protobufs.