Skip to content

Instantly share code, notes, and snippets.

@gistlyn gistlyn/Program.java
Last active Dec 30, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.