Nicholas DiPiazza
Nicholas DiPiazza

Reputation: 10585

gRPC - make a channel to the same server

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?

Upvotes: 5

Views: 2173

Answers (1)

Eric Anderson
Eric Anderson

Reputation: 26394

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.

Upvotes: 5

Related Questions