<dependency>
<groupId>com.github.wmz7year</groupId>
<artifactId>ThriftConnectionPool</artifactId>
<version>1.0.6-RELEASE</version>
</dependency>
ThriftConnectionPoolConfig config = new ThriftConnectionPoolConfig();
config.setConnectTimeout(3000);
config.setThriftProtocol(TProtocolType.BINARY);
config.setClientClass(Example.Client.class);
config.addThriftServer("127.0.0.1", 9119);
config.setMaxConnectionPerServer(2);
config.setMinConnectionPerServer(1);
config.setIdleMaxAge(2, TimeUnit.SECONDS);
config.setMaxConnectionAge(2);
config.setLazyInit(false);
try {
ThriftConnectionPool<Example.Client> pool = new ThriftConnectionPool<Example.Client>(config);
Example.Client client = pool.getConnection().getClient();
client.ping();
pool.close();
} catch (ThriftConnectionPoolException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ThriftConnectionPoolConfig config = new ThriftConnectionPoolConfig(ThriftServiceType.MULTIPLEXED_INTERFACE);
config.setConnectTimeout(3000);
config.setThriftProtocol(TProtocolType.BINARY);
config.addThriftServer("127.0.0.1", 9119);
config.addThriftClientClass("other", Other.Client.class);
config.addThriftClientClass("example", Example.Client.class);
config.setMaxConnectionPerServer(2);
config.setMinConnectionPerServer(1);
config.setIdleMaxAge(2, TimeUnit.SECONDS);
config.setMaxConnectionAge(2);
config.setLazyInit(false);
config.setAcquireIncrement(2);
config.setAcquireRetryDelay(2000);
config.setAcquireRetryAttempts(1);
config.setMaxConnectionCreateFailedCount(1);
config.setConnectionTimeoutInMs(5000);
config.check();
ThriftConnectionPool<TServiceClient> pool = new ThriftConnectionPool<TServiceClient>(config);
ThriftConnection<TServiceClient> connection = pool.getConnection();
// example service
com.wmz7year.thrift.pool.example.Example.Client exampleServiceClient = connection.getClient("example",
Example.Client.class);
exampleServiceClient.ping();
// other service
com.wmz7year.thrift.pool.example.Other.Client otherServiceClient = connection.getClient("other",
Other.Client.class);
otherServiceClient.ping();
pool.close();
1、补充文档
2、补充性能测试
3、完善使用例子
4、操作重试机制?