我正在尝试构建一个异步节俭客户端。下面是我正在构建的代码
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。
基本上,必须使用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);