python迅雷sdk_Python anthunder包_程序模块 - PyPI - Python中文网
安敦達(又名沙發螺栓Python)
anthunder(ant thunder)是一個用python編寫的沙發螺栓庫。
它支持通過“sofa bolt+protobuf”協議調用rpc。
要求python3>;=3.4(aio類需要異步支持)
python2.7(支持有限,需要額外的第三方庫)
mosn>;=1.3(用于版本>;=0.6)
mosn<;1.3(用于<;0.6版)
路線圖[X]螺栓客戶端(protobuf序列化)
[X]通過Mosn發現服務(沙發服務網側車)
[X]螺栓服務器(protobuf序列化)
[]Hessian2序列化支持
教程
作為客戶(呼叫者)獲取.proto文件
執行protoc --python_out=. *.proto編譯protobuf文件,并獲取_pb2.py文件。
導入protobuf類(用_pb2后綴)fromSampleServicePbResult_pb2importSampleServicePbResultfromSampleServicePbRequest_pb2importSampleServicePbRequestfromanthunderimportAioClientspanctx=SpanContext()# generate a new context, an object of mytracer.SpanContext, stores rpc_trace_context.# spanctx = ctx # or transfered from upstream rpcclient=AioClient(my_app_name)# my_app_name will be send to sidecar as caller name.# will create a thread, and send heartbeat to mesh every 30sinterface='com.alipay.rpc.common.service.facade.pb.SampleServicePb:1.0'# Subscribe interfaceclient.subscribe(interface)# Call synchronouslycontent=client.invoke_sync(interface,"hello",SampleServicePbRequest(name=some_name).SerializeToString(),timeout_ms=500,spanctx=spanctx)result=SampleServicePbResult()result.ParseFromString(content)# Call asynchronouslydefclient_callback(resp):# callback function, accepts bytes as the only argument,# then do deserialize and further processesresult=SampleServicePbResult()result.ParseFromString(content)# do somethingfuture=client.invoke_async(interface,"hello",SampleServicePbRequest(name=some_name).SerializeToString(),spanctx=spanctx,callback=client_callback))
有關可運行的演示,請參見項目的unittest
作為服務器fromanthunder.listenerimportaio_listenerclassSampleService(object):def__init__(self,ctx):# service must accept one param as spanctx for rpc tracing supportself.ctx=ctxdefhello(self,bs:bytes):obj=SampleServicePbRequest()obj.ParseFromString(bs)print("Processing Request",obj)returnSampleServicePbResult(result=obj.name).SerializeToString()listener=aio_listener.AioListener(('127.0.0.1',12200),"test_app")# register interface and its function, plus its protobuf definition classlistener.handler.register_interface("com.alipay.rpc.common.service.facade.pb.SampleServicePb:1.0",SampleService)# start server in a standalone threadlistener.run_threading()# or start in current threadlistener.run_forever()# publish interfaces to service meshlistener.publish()# shutdown the serverlistener.shutdown()
許可證
版權所有(c)2018年至今,螞蟻金融服務集團
apache許可證2.0
請參閱許可證文件。
第三方
mysockpool包的一部分使用來自urllib3項目的代碼
根據麻省理工學院的許可證。請參閱mysockpool包下的origin-license.txt。
發布歷史記錄
0.5.6(2019-03-15)
錯誤修復修復解析協議時出現的無限循環錯誤
0.5.4(2018-11-09)
錯誤修復修復python2.7下的服務器錯誤
0.5.3(2018-08-27)
功能支持AntShareCloud參數。
0.5.2(2018-09-03)
錯誤修復修復python2.7下的各種錯誤
0.5.1(2018-08-31)
錯誤修復sofa trace rpc id可能包含str.
歡迎加入QQ群-->: 979659372
推薦PyPI第三方庫
總結
以上是生活随笔為你收集整理的python迅雷sdk_Python anthunder包_程序模块 - PyPI - Python中文网的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python第三方库文件传输_pytho
- 下一篇: python tkinter控件_如何实