您好,登錄后才能下訂單哦!
原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請注明:轉(zhuǎn)載自IT人故事會,謝謝!
原文鏈接地址:『高級篇』docker之Python開發(fā)信息服務(wù)(11)信息服務(wù)準(zhǔn)備用python來寫,在現(xiàn)有的idea中添加python的模塊。源碼:https://github.com/limingios/msA-docker
安裝后重新idea。
開始我用idea寫python,下載個插件都費(fèi)勁,我換成了pycharm來寫美滋滋
# coding: utf-8
from message.api import MessageService
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
class 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 True
if __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")
都是根據(jù)thrift文件,生成對應(yīng)的上級目錄
thrift --gen py -out ../ message.thrift thrift --gen java -out ../ message.thrift
PS:thrift的開發(fā)流程是: 先定義thrift的文件,然后通過命令生成對應(yīng)的python代碼。通過實(shí)現(xiàn)定義的thrift方法,來完成thrift的調(diào)用。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。