Skip to main content

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.

[connection_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
import thrift_connector.connection_pool as connection_pool

service = thriftpy.load("pingpong_app/pingpong.thrift")
pool = connection_pool.ClientPool(
    service.PingService,
    'localhost',
    8880,
    connection_class=connection_pool.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
import connection_pool

pool = connection_pool.ClientPool(
    PingService,
    'localhost',
    8880,
    connection_class=connection_pool.ThriftClient
    )

print "Sending Ping..."
print "Receive:", pool.ping()
print "Winning the match..."
print "Receive:", pool.win()

Test

py.test tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thrift_connector-0.21.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

thrift_connector-0.21-py2-none-any.whl (6.7 kB view details)

Uploaded Python 2

File details

Details for the file thrift_connector-0.21.tar.gz.

File metadata

File hashes

Hashes for thrift_connector-0.21.tar.gz
Algorithm Hash digest
SHA256 d08acec64cee45f081f3fa82977cf17d3d9d63c70b162e11c2adeb16075ebe38
MD5 939bacdbd489a4d9d0649ddf4a702863
BLAKE2b-256 9163c85991f31b781802a4afa209cd032cea7db8016b367f2a4b155e20df439a

See more details on using hashes here.

File details

Details for the file thrift_connector-0.21-py2-none-any.whl.

File metadata

File hashes

Hashes for thrift_connector-0.21-py2-none-any.whl
Algorithm Hash digest
SHA256 f2934dd0c9fa34644ef567b09e553cd21aace25d042d3d1049b07feb8e2e1f00
MD5 9e0cba40823f2d9c3a785d5d8ead52d6
BLAKE2b-256 f6a02d34db72433eb9a52511a046a035fcceb095586de4c28711c14789281ccc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page