Package io.grpc

The gRPC core public API.

gRPC is based on a client-server model of remote procedure calls. A client creates a channel which is connected to a server. RPCs are initiated from the client and sent to the server which then responds back to the client. When the client and server are done sending messages, they half close their respective connections. The RPC is complete as soon as the server closes.

To send an RPC, first create a Channel using ManagedChannelBuilder.forTarget(java.lang.String). When using auto generate Protobuf stubs, the stub class will have constructors for wrapping the channel. These include newBlockingStub, newStub, and newFutureStub which you can use based on your design. The stub is the primary way a client interacts with a server.

To receive RPCs, create a Server using ServerBuilder.forPort(int). The Protobuf stub will contain an abstract class called AbstractFoo, where Foo is the name of your service. Extend this class, and pass an instance of it to ServerBuilder.addService(io.grpc.ServerServiceDefinition). Once your server is built, call Server.start() to begin accepting RPCs.

Both Clients and Servers should use a custom Executor. The gRPC runtime includes a default executor that eases testing and examples, but is not ideal for use in a production environment. See the associated documentation in the respective builders.

Clients and Servers can also be shutdown gracefully using the shutdown method. The API to conduct an orderly shutdown is modeled from the ExecutorService.

gRPC also includes support for more advanced features, such as name resolution, load balancing, bidirectional streaming, health checking, and more. See the relative methods in the client and server builders.

Development of gRPC is done primary on Github at https://github.com/grpc/grpc-java, where the gRPC team welcomes contributions and bug reports. There is also a mailing list at grpc-io if you have questions about gRPC.