-
Notifications
You must be signed in to change notification settings - Fork 3
/
pool.rs
31 lines (27 loc) · 999 Bytes
/
pool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use hbase_thrift::hbase::{HbaseSyncClient, THbaseSyncClient};
use r2d2::Pool;
use thrift::{
protocol::{TBinaryInputProtocol, TBinaryOutputProtocol},
transport::{
ReadHalf, TBufferedReadTransport, TBufferedWriteTransport, TTcpChannel, WriteHalf,
},
};
use thrift_pool::{MakeThriftConnectionFromAddrs, ThriftConnectionManager};
type Client = HbaseSyncClient<
TBinaryInputProtocol<TBufferedReadTransport<ReadHalf<TTcpChannel>>>,
TBinaryOutputProtocol<TBufferedWriteTransport<WriteHalf<TTcpChannel>>>,
>;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manager = ThriftConnectionManager::new(MakeThriftConnectionFromAddrs::<Client, _>::new(
"localhost:9090",
));
let pool = Pool::builder().build(manager)?;
let mut conn = pool.get()?;
let tables: Vec<_> = conn
.get_table_names()?
.into_iter()
.map(String::from_utf8)
.collect();
println!("pooled connection returned: {:?}", tables);
Ok(())
}