Package: anthunder
anthunder(a.k.a. sofa-bolt-python)anthunder(ant thunder) is a sofa-bolt library written in python.
It supports RPC calling via 'sofa-bolt + protobuf' protocol.requirementspython3 >= 3.5 (aio classes needs asyncio support)python2.7 (limited support, needs extra 3rd party libraries)mosn >= 1.3 (to use with version >= 0.6)mosn < 1.3 (to use with version < 0.6)roadmapbolt client(protobuf serialization)service discover via mosn (sofa servicemesh sidecar)bolt server(protobuf serialization)hessian2 serialization supportTutorialAs client (caller)Acquire.protofileExecuteprotoc --python_out=. *.prototo compile protobuf file, and get_pb2.pyfile.Import protobuf classes (postfixed with_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))See project's unittest for runnable demoAs serverfromanthunder.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()LicenseCopyright (c) 2018-present, Ant Financial Service GroupApache License 2.0See LICENSE file.ThirdpartyPart of the mysockpool package uses codes fromurllib3project
under the term of MIT License. See origin-license.txt under the mysockpool package.Release History0.5.6 (2019-03-15)Bugfixesfix a infinite loop bug when parsing protocol0.5.4 (2018-11-09)Bugfixesfix server errors under python2.70.5.3 (2018-08-27)Featuresupport antsharecloud parameters.0.5.2 (2018-09-03)Bugfixesfix various errors under python2.70.5.1 (2018-08-31)Bugfixessofa trace rpc id may contains str.