ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port)
.usePlaintext()
.build();
HelloServiceGrpc.HelloServiceBlockingStub stub =
HelloServiceGrpc.newBlockingStub(channel);
HelloResponse response = stub.sayHello(HelloRequest.newBuilder()
.setName("John")
.build());
channel.shutdown();
ChannelPool pool = ChannelPoolBuilder.newBuilder()
.maxTotal(10)
.idleTimeout(Duration.ofMinutes(5))
.build();
ManagedChannel channel = pool.borrowChannel(host, port);
pool.returnChannel(channel);
pool.close();
StreamServiceGrpc.StreamServiceStub stub =
StreamServiceGrpc.newStub(channel);
StreamObserver<Request> requestObserver = stub.myMethod(new StreamObserver<Response>() {
@Override
public void onNext(Response response) {
System.out.println("Received response: " + response);
}
@Override
public void onError(Throwable t) {
System.err.println("Error: " + t.getMessage());
}
@Override
public void onCompleted() {
System.out.println("Completed");
}
});
for (int i = 0; i < 10; i++) {
requestObserver.onNext(Request.newBuilder()
.setData("Data " + i)
.build());
}
requestObserver.onCompleted();
ServerBuilder.forPort(port)
.maxInboundMessageSize(10 * 1024 * 1024) // 10MB
.build();
ManagedChannelBuilder.forAddress(host, port)
.maxInboundMessageSize(10 * 1024 * 1024) // 10MB
.build();