This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
use tns in your project
jerry edited this page Apr 21, 2017
·
10 revisions
!!! 接入tns(thrift name server),需要以下几步:
- 导入poolAble.thrift
- 让自己的
service extends poolAble.thrift
- 以
TBinaryProtocol
启动thrift server - 在tns中loadservice列表
- 完成以上几步,cluster就构建完毕了
<dependency>
<groupId>com.github.jerrysearch</groupId>
<artifactId>tns-client</artifactId>
<version>3.0.2</version>
</dependency>
- 在client中构建ClusterPool及ServicePool
ClusterPool clusterPool = new ClusterPool("D2", "D3", "D4");
ServicePool pool = new ServicePool(clusterPool, "drpc", 10);
注:
ClusterPool建议单例。ClusterPool负责监听tns的变化,一个即可
ServicePool建议一个service保持一个pool即可,ServicePool负责监听单个service的变化
- 取一个tsnode
TSNode tsnode = pool.getOne();
- 用这个thrift service node执行业务
移除一个tsnode
pool.brokenNode(tsnode);
Good Wishes
jerry