雷声是沙发螺栓协议库。

anthunder的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序列化支持

教程

作为客户(呼叫者)

  1. 获取.proto文件
  2. 执行protoc --python_out=. *.proto编译protobuf文件,并获取_pb2.py文件。
  3. 导入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 Python中文网_新手群

推荐PyPI第三方库


热门话题
eclipse如何将LWUIT主题文件加载到Java项目中?   JavaJPA HibernateFetchType。渴望和获取模式。加入非主键   java为单个和多个对象创建对象容器   java在到达末尾时在viewpager2中加载更多项目   java我怎么能忽略它。解压时存储DS_和MACOSX文件?   java我无法使用ApachePOI3.10读取xlsx文件   java为什么我在Android应用程序的webView中看到广告(我没有注册任何广告)   在Java中,PrintWriter write()方法在哪里写入数据   c#ProcessStartInfo挂在“WaitForExit”上?为什么?   安卓中的java解析查询问题   java Android摄像头在拍照时禁用   爪哇交货过早地从jsprit的仓库提货   java退避算法仿真   java我的计数反转算法有什么问题?   java什么导致一个类中的变量受到另一个类的影响?   JavaVaadin和Spring引导问题   java无法使用writerInterceptor拦截jersey资源方法   java如何根据配置选择RedisCluster、RedisStandalone和Sentinel连接?   java GSON/如何解析数字   java:字节码中的字符串concat转换为StringBuilder