当前位置: 首页 > news >正文

潍坊门户网站建设做百度网站费用

潍坊门户网站建设,做百度网站费用,免费游戏网页入口,九天智能建站软件以下是一个 使用多路复用#xff08;TMultiplexedProtocol#xff09; 的 Thrift 客户端完整流程和关键函数#xff08;以 Java 为例#xff09;#xff0c;适用于当服务端使用 TMultiplexedProcessor 注册了多个服务时#xff0c;客户端可以区分并调用不同的服务。 ✅ 客… 以下是一个 使用多路复用TMultiplexedProtocol 的 Thrift 客户端完整流程和关键函数以 Java 为例适用于当服务端使用 TMultiplexedProcessor 注册了多个服务时客户端可以区分并调用不同的服务。 ✅ 客户端整体流程使用 TMultiplexedProtocol 1. 定义多个服务以两个为例 // example1.thrift namespace java exampleservice ExampleService1 {string sayHello(1:string name) }// example2.thrift namespace java exampleservice ExampleService2 {i32 add(1:i32 a, 2:i32 b) } 使用 Thrift 编译器生成 Java 代码 thrift --gen java example1.thrift thrift --gen java example2.thrift 2. 服务端使用多路复用服务端部分简略 TMultiplexedProcessor multiplexedProcessor new TMultiplexedProcessor();multiplexedProcessor.registerProcessor(ExampleService1, new ExampleService1.Processor(new ExampleService1Impl())); multiplexedProcessor.registerProcessor(ExampleService2, new ExampleService2.Processor(new ExampleService2Impl()));TServerTransport serverTransport new TServerSocket(9090); TServer server new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(multiplexedProcessor)); server.serve(); 3. 客户端实现核心 import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TMultiplexedProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport;import example.ExampleService1; import example.ExampleService2;public class ThriftClient {public static void main(String[] args) {TTransport transport null;try {// 1. 打开传输层连接transport new TSocket(localhost, 9090);transport.open();// 2. 创建基础协议TProtocol baseProtocol new TBinaryProtocol(transport);// 3. 使用多路复用协议针对不同服务TMultiplexedProtocol protocol1 new TMultiplexedProtocol(baseProtocol, ExampleService1);TMultiplexedProtocol protocol2 new TMultiplexedProtocol(baseProtocol, ExampleService2);// 4. 创建客户端 Stub代理ExampleService1.Client client1 new ExampleService1.Client(protocol1);ExampleService2.Client client2 new ExampleService2.Client(protocol2);// 5. 调用服务方法String greeting client1.sayHello(Alice);int result client2.add(5, 7);System.out.println(Service1 response: greeting);System.out.println(Service2 response: result);} catch (Exception e) {e.printStackTrace();} finally {// 6. 关闭连接if (transport ! null) {transport.close();}}} } 4. C 版本客户端实现 客户端代码C #include #include #include #include #include ExampleService1.h #include ExampleService2.husing namespace apache::thrift; using namespace apache::thrift::protocol; using namespace apache::thrift::transport;int main() {try {// 客户端连接std::shared_ptr socket(new TSocket(localhost, 9090));std::shared_ptr transport(new TBufferedTransport(socket));std::shared_ptr protocol(new TBinaryProtocol(transport));transport-open();// 使用多路复用协议TMultiplexedProtocol protocol1(protocol, ExampleService1);TMultiplexedProtocol protocol2(protocol, ExampleService2);// 创建客户端ExampleService1Client client1(protocol1);ExampleService2Client client2(protocol2);// 调用服务std::string greeting;client1.sayHello(greeting, Alice);std::cout Response from ExampleService1: greeting std::endl;int result;client2.add(result, 5, 7);std::cout Response from ExampleService2: result std::endl;transport-close();} catch (const std::exception e) {std::cerr Error: e.what() std::endl;}return 0; }客户端关键类和函数说明 类 / 函数 作用说明 TSocket(host, port) 创建客户端传输连接基于 TCP transport.open() 打开连接 TBinaryProtocol 使用二进制协议进行编码 TMultiplexedProtocol 多路复用协议用于标识服务名称 ExampleService1.Client 客户端代理调用服务方法 client1.sayHello(Alice) 实际调用远程服务端方法 transport.close() 关闭连接 ✅ 小提示 多路复用的关键是 服务端使用 TMultiplexedProcessor 注册服务带名字客户端用 TMultiplexedProtocol 创建不同服务的协议实例带同样的名字。
http://www.pierceye.com/news/249182/

相关文章:

  • 帮别人做网站赚钱吗中山快速建站合作
  • 保靖网站建设做网站要运用到代码吗
  • 我用织梦5.7做个网站应该把淘宝客店铺链接放到哪frontpage可以制作网页吗
  • 潍坊优化网站排名在线网页设计培训机构
  • c做的网站ps做 网站标准尺寸
  • 老虎淘客系统可以做网站吗wordpress po mo
  • 网站的建设与维护那个网站做图片好
  • 昆山网站建设详细方案建设企业网站初始必备的六大功能
  • 做网站是前端还是后端网站规划 设计 制作 发布与管理过程
  • 黄山网站开发威县做网站哪里便宜
  • 网站怎么分类视频聚合网站怎么做不侵权
  • 有没有做问卷还能赚钱的网站套别人的网站模板吗
  • 东莞做汽车有没有买票的网站做谷歌推广一个月赚10万
  • 抚州城乡建设厅网站建设局官网查询
  • 汉中微信网站建设装修3d效果图怎么制作
  • wordpress 主题放哪站内关键词自然排名优化
  • 网站备案后经营做网站实例教程
  • 软件网站怎么做的python下载安装教程
  • 旅游网站开发分析报告网站建设教程搭建芽嘱湖南岚鸿信赖
  • 网站的配色方案高校网站建设意义
  • 滇中引水工程建设管理局网站网站开发怎样验收
  • ps制作网站logo阿里云网站备案拍照
  • 网站建设合同】wordpress翻书
  • 电商网站建设制作隆化县建设局网站
  • 宁波网站建设rswl网页美工设计教案
  • 贵州省住房城乡建设部网站json网站开发
  • 桥头网站仿做百度里面的站长工具怎么取消
  • 博物馆网站页面设计说明山东高端网站定制
  • python网站开发效率jsp做网站下载图片
  • 营销式网站建设免费注册个人网站官网