Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active December 30, 2019 08:07
Show Gist options
  • Save gistlyn/15e2446f7787fe19629ecbc36d7f3f99 to your computer and use it in GitHub Desktop.
Save gistlyn/15e2446f7787fe19629ecbc36d7f3f99 to your computer and use it in GitHub Desktop.
Java Google protoc SSL gRPC Service Client TodoWorld Example
import io.grpc.ManagedChannel;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import java.io.File;
public class Program {
public static void main(String[] args) throws javax.net.ssl.SSLException {
ManagedChannel channel = NettyChannelBuilder.forAddress(
"todoworld.servicestack.net", 50051)
.sslContext(GrpcSslContexts.forClient()
.trustManager(new File(Program.class.getClassLoader().getResource("grpc.crt").getFile()))
.build())
.build();
GrpcServicesGrpc.GrpcServicesBlockingStub client = GrpcServicesGrpc.newBlockingStub(channel);
Services.Hello request = Services.Hello.newBuilder().setName("gRPC Java").build();
String result = client.getHello(request).getResult();
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment