异步节俭客户端中的传递URI /上下文路径

问题描述 投票:1回答:1

我正在尝试构建一个异步节俭客户端。下面是我正在构建的代码

TNonblockingTransport transport = new TNonblockingSocket("127.0.0.1", 8080);
TAsyncClientManager clientManager = new TAsyncClientManager();
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TCalculator.AsyncClient client = new TCalculator.AsyncClient(protocolFactory,clientManager,transport); 

我的服务器在http://localhost:8080/calculator上运行

您能帮我在这里通过uri吗?

如果是同步客户端,这很简单。

 TTransport transport;
  transport = new THttpClient("http://localhost:"+8080+"/calculator");
 transport.open();

Stacks used: Spring boot 2.2.1 & thrift.9

或者我正在错误地创建TNonblockingTransport。

java spring-boot thrift
1个回答
0
投票

基本上,必须使用TNonblockingSocket才能以非阻塞方式使用传输。更改传输定义以使用SocketChannel configuration,如下所示:

InetSocketAddress将为您接受端口和URL:

 try (SocketChannel socketChannel = SocketChannel.open()) {
        socketChannel.connect(new InetSocketAddress("localhost", port));
        TNonblockingTransport transport = new TNonblockingSocket(socketChannel);
}

 final Asker.AsyncClient client = new Asker.AsyncClient(
                new TCompactProtocol.Factory(),
                new TAsyncClientManager(), transport);
© www.soinside.com 2019 - 2024. All rights reserved.