GithubHelp home page GithubHelp logo

baeeq / thrift-connection-pool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wmz7year/thrift-connection-pool

0.0 3.0 0.0 173 KB

Apache Thrift客户端连接池(client connection pool)

License: Apache License 2.0

Java 99.88% Thrift 0.12%

thrift-connection-pool's Introduction

#Thrift连接池实现

Join the chat at https://gitter.im/wmz7year/Thrift-Connection-Pool Build Status

##特性

  • 1、支持服务器之间的负载均衡
  • 2、每个服务器拥有一个独立的连接分区 所有的连接分区合并一起为整个连接池
  • 3、连接池支持自动创建连接、管理超时连接、管理失效连接
  • 4、支持服务器列表动态增加或者移除
  • 5、支持自动调取ping方法(在thrift描述文件添加方法void ping(),)检测连接可用性
  • 6、支持当服务不可用时自动将对应的服务器剔除连接池的功能
  • 7、添加多服务接口支持

###下载

<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、操作重试机制?

thrift-connection-pool's People

Contributors

wmz7year avatar gitter-badger avatar

Watchers

James Cloos avatar baeeq avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.