1 Star 0 Fork 1

光魔科技/vertx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Client.java 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
Clement Escoffier 提交于 2017-05-22 09:09 . A simple example using SSL.
package io.vertx.example.grpc.ssl;
import io.grpc.ManagedChannel;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.net.JksOptions;
import io.vertx.example.grpc.util.Runner;
import io.vertx.grpc.VertxChannelBuilder;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class Client extends AbstractVerticle {
public static void main(String[] args) {
Runner.runExample(Client.class);
}
@Override
public void start() throws Exception {
ManagedChannel channel = VertxChannelBuilder
.forAddress(vertx, "localhost", 8080)
.useSsl(options -> options.setSsl(true)
.setUseAlpn(true)
.setTrustStoreOptions(new JksOptions()
.setPath("tls/client-truststore.jks")
.setPassword("wibble")))
.build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
stub.sayHello(request, asyncResponse -> {
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/3kgz/vertx-examples.git
git@gitee.com:3kgz/vertx-examples.git
3kgz
vertx-examples
vertx-examples
master

搜索帮助