Last active
December 30, 2019 08:07
-
-
Save gistlyn/15e2446f7787fe19629ecbc36d7f3f99 to your computer and use it in GitHub Desktop.
Java Google protoc SSL gRPC Service Client TodoWorld Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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