您好,登錄后才能下訂單哦!
原創文章,歡迎轉載。轉載請注明:轉載自IT人故事會,謝謝!
原文鏈接地址:『高級篇』docker之Python開發信息服務(11)信息服務準備用python來寫,在現有的idea中添加python的模塊。源碼:https://github.com/limingios/msA-docker
安裝后重新idea。
開始我用idea寫python,下載個插件都費勁,我換成了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")
都是根據thrift文件,生成對應的上級目錄
thrift --gen py -out ../ message.thrift thrift --gen java -out ../ message.thrift
PS:thrift的開發流程是: 先定義thrift的文件,然后通過命令生成對應的python代碼。通過實現定義的thrift方法,來完成thrift的調用。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。