python's tornado的异步xml-rpc和fastprc客户端
tornado-fastrpc的Python项目详细描述
非阻塞XML-RPC和FastRPC(请参见https://github.com/seznam/fastrpc) Python龙卷风的客户。如果fastrpc不可用,则仅xml-rpc 将支持协议。Python2.7和Python3.4(或更高版本)是 支持。
安装
要求:
- pycurl
- 龙卷风3.2或更高
可选要求:
- fastrpc(libfastrpc+fastrpcpython的模块)
安装和测试:
python setup.py install python setup.py test
构建debian jessie包(需要dpkg-buildpackage+lintian 以及debian/control文件中Build-Depends选项中的依赖项。
python setup.py bdist_deb
ussage
proxy = ServerProxy('http://example.com/RPC2:8000', connect_timeout=5.0, timeout=5.0, use_binary=True) class BazHandler(tornado.web.RequestHandler): @tornado.gen.coroutine def get(self): try: res = yield proxy.getData(123) except Exception as e: self.write('Error: {}'.format(e)) else: self.write('Data: {}'.format(res.value)) class BarHandler(tornado.web.RequestHandler): @tornado.gen.coroutine def get(self): res = yield proxy.getData(123, quiet=True) if res.success: self.write('Data: {}'.format(res.value)) else: self.write('Error: {}'.format(res.exception))
文件
服务器代理类
classtornado_fastrpc.client.serverproxy(uri, 连接超时=5.0,超时=5.0,使用二进制=false,用户代理=none, keep_alive=false,使用_http10=true,http_proxy=none,max_clients=10)
Async FastRPC client for Tornado, tt uses ^{tt5}$ backend. Manages communication with a remote RPC server.
- url<string>
- URL address
- connect_timeout<float>
- Timeout for initial connection in seconds
- request_timeout<float>
- Timeout for entire request in seconds
- use_binary<bool>
- Force binary protocol
- user_agent<string>
- User-Agent string
- keep_alive<bool>
- Allow keep-alive connection
- use_http10<bool>
- Force HTTP/1.0 protocol instead of HTTP/1.1
- http_proxy<string>
- HTTP proxy, eg. http://user:pass@example.com:80
- max_clients<int>
- Size of the Curl’s connection pool
结果对象
classtornado_fastrpc.client.Result(success,value,exception)
FastRPC调用的返回类型。包含属性:
- success<bool>
- ^{tt6}$ if operation succeeded, else ^{tt7}$
- value
- contains returning value if operation succeeded, else ^{tt8}$
- exception<bool>
- contains instance of the exception if operation failed, else ^{tt8}$
故障对象
classtornado_fastrpc.client.fault(faultcode,faultstring)
Exception, indicates an XML-RPC error.
- faultCode<string>
- Error code
- faultString<string>
- Error message
许可证
3条款BSD