Lib to connect to thrift services with pools
Project description
Simple connection pool for thrift. thrift_connector can be used both for native thrift client and thriftpy client with minor difference in usage.
Examples can be found in examples as well as the following sections.
Options
- service
Defined thrift service. It should be the container class of apis for thriftpy (thriftpy.load(’…’).XXXService), and api module for thrift (XXX_sdk.xxx.xxxService)
- host
Server host
- port
Server port
- [timeout]
Socket timeout, in seconds.
- [name]
Connection pool name, for identity.
- [raise_empty]
Whether to raise exception if pool is empty while trying to obtain a connection.
- [max_conn]
Number of connections to manage in pool.
- [connction_class]
Connection class implementation. Builtin classes are: ThriftClient for native thrift, ThriftPyClient and ThriftPyCyClient for thriftpy, the latter one utilizes Cython for better performance.
- [keepalive]
Seconds each connection is able to stay alive. If oen connection has lived longer than this period, it will be closed.
Usage
Examples for thriftpy is:
import thriftpy
from thrift_connector import ClientPool, ThriftPyCyClient
service = thriftpy.load("pingpong_app/pingpong.thrift")
pool = ClientPool(
service.PingService,
'localhost',
8880,
connction_class=ThriftPyCyClient
)
print "Sending Ping..."
print "Receive:", pool.ping()
print "Winning the match..."
print "Receive:", pool.win()
Examples for thrift is:
# -*- coding: utf-8 -*-
from pingpong_app.pingpong_sdk.pingpong import PingService
from thrift_connector import ClientPool, ThriftClient
pool = ClientPool(
PingService,
'localhost',
8880,
connction_class=ThriftClient
)
print "Sending Ping..."
print "Receive:", pool.ping()
print "Winning the match..."
print "Receive:", pool.win()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file thrift_connector-0.3.tar.gz
.
File metadata
- Download URL: thrift_connector-0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b990cc99a3f107c5c3ab985ff5b87d63f43df1390b4a305c4cd17e199da1ed3 |
|
MD5 | 391f5743321deda825bffc87d8acd8c3 |
|
BLAKE2b-256 | 2706b68bfa19c2fd6878365f6112b1a974170fd6c44fe78659163ecb8148b46e |
File details
Details for the file thrift_connector-0.3-py2-none-any.whl
.
File metadata
- Download URL: thrift_connector-0.3-py2-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e4e448045f42cb3cf4781459c7c5fc943cd43711e50e0eb7de12748023f169 |
|
MD5 | bb37bc6fded131d97e76906f1ad94802 |
|
BLAKE2b-256 | 39d573dc31236727ff0ef16c6f07670afcb455791c9f09368460337236961099 |