李明
|
idea安装python插件
安装python模块
安装thrift的pyhon插件
# coding: utf-8from message.api import MessageServicefrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom thrift.server import TServerclass MessageServiceHandler: def sendMobileMessage(self, mobile, message): print ("sendMobileMessage, mobile:"+mobile+", message:"+message) return True def sendEmailMessage(self, email, message): print ("sendEmailMessage, email:"+email+", message:"+message) return Trueif __name__ == '__main__': handler = MessageServiceHandler() processor = MessageService.Processor(handler) transport = TSocket.TServerSocket(None, "9090") tfactory = TTransport.TFramedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) print ("python thrift server start") server.serve() print ("python thrift server exit")
thrift --gen py -out ../ message.thrift thrift --gen java -out ../ message.thrift PS:thrift的开发流程是: 先定义thrift的文件,然后通过命令生成对应的python代码。通过实现定义的thrift方法,来完成thrift的调用。
|
2019-01-27 01:45:17