def mk_client_with_url(self): return make_client( addressbook.AddressBookService, proto_factory=self.PROTOCOL_FACTORY, trans_factory=self.TRANSPORT_FACTORY, url='thrift://127.0.0.1:{port}'.format(port=self.port))
#!/usr/bin/env python # -*- coding: utf-8 -*- # FileName : thrift_client.py # Author : wuqingfeng@ import thriftpy2 from thriftpy2.rpc import make_client if __name__ == '__main__': time_thrift = thriftpy2.load("time_service.thrift", module_name="time_thrift") client = make_client(time_thrift.TimeService, '127.0.0.1', 6000) print(client.get_time())
def client_start(): partition_thrift = thriftpy.load('partition.thrift', module_name='partition_thrift') return make_client(partition_thrift.Partition, '127.0.0.1', 6000)
def mk_client(self): return make_client(addressbook.AddressBookService, '127.0.0.1', self.port, proto_factory=self.PROTOCOL_FACTORY, trans_factory=self.TRANSPORT_FACTORY)
#!/usr/bin/python # -*- coding: utf-8 -*- # @Time : 2019/7/20 14:12 # @Author : wangyong # @Desc : import thriftpy2 # from thriftpy2.rpc import client_context from thriftpy2.rpc import make_client # 读入thrift文件,module_name最好与server端保持一致,也可以不保持一致 message_thrift = thriftpy2.load("message.thrift", module_name="message_thrift") if __name__ == '__main__': client = make_client(message_thrift.MessageService, '127.0.0.1', 9090) print(client.ping()) print(client.sayHello()) print(client.sendMobileMessage("137", "mobile消息")) print(client.sendEmailMessage("137", "email消息")) print("发送完成")
from typing import TYPE_CHECKING from example.app import interfaces from thriftpy2.rpc import make_client if TYPE_CHECKING: from example.app.interfaces.todo import Todo if __name__ == "__main__": client: "Todo" = make_client(interfaces.todo.Todo, "127.0.0.1", 6000) todo_id = client.create(text="item", type=interfaces.todo.TodoType.NOTE) print(f"CREATE = {todo_id}") print(f"GET = {client.get(id=todo_id)}") try: client.get(id=todo_id + 1) except interfaces.shared.NotFound: print(f"NOT FOUND")
def client(self): return make_client(self.ARTICLEMETA_THRIFT.ArticleMeta, self._address, self._port, timeout=self._timeout)
def make_client(self, service, **kwargs): return make_client(self.thrift.__getattribute__(service), **kwargs)
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # ############################################################################# # File Name : client.py # Author : DaiDai # Mail : [email protected] # Created Time: 三 3/31 14:58:05 2021 # ############################################################################# import thriftpy2 from thriftpy2.rpc import make_client if __name__ == "__main__": pingpong_thrift = thriftpy2.load("pingpong.thrift", module_name="pingpong_thrift") client = make_client(pingpong_thrift.PingPong, '127.0.0.1', 6000) print(client.ping())
import thriftpy2 from thriftpy2.rpc import make_client exam_thrift = thriftpy2.load("./thrift_idl/exam.thrift", module_name="exam_thrift") exam_client = make_client(exam_thrift.ExamService, '81.68.117.198', 9091) user_thrift = thriftpy2.load("./thrift_idl/user.thrift", module_name="user_thrift") user_client = make_client(user_thrift.UserService, '81.68.117.198', 9092) analysis_thrift = thriftpy2.load("./thrift_idl/analysis.thrift", module_name="analysis_thrift") analysis_client = make_client(analysis_thrift.AnalysisService, '81.68.117.198', 9093, timeout=10000) question_thrift = thriftpy2.load("./thrift_idl/question.thrift", module_name="question_thrift") question_client = make_client(question_thrift.QuestionService, '81.68.117.198', 9094, timeout=10000)
import thriftpy2 from thriftpy2.rpc import make_client user_thrift = thriftpy2.load( "https://raw.githubusercontent.com/llf-970310/expression-api/master/thrift_idl/user.thrift", module_name="user_thrift") user_client = make_client(user_thrift.UserService, '81.68.117.198', 9092)