Thrift 异步调用
来源:互联网 发布:大数据发展趋势 ppt 编辑:程序博客网 时间:2024/06/10 16:34
服务端
import org.apache.thrift.TProcessor;import org.apache.thrift.protocol.TCompactProtocol;import org.apache.thrift.server.TNonblockingServer;import org.apache.thrift.server.TServer;import org.apache.thrift.transport.TFramedTransport;import org.apache.thrift.transport.TNonblockingServerSocket;import org.apache.thrift.transport.TTransportException;import com.whr.rpc.service.MessageForwardsService;public class MessageForwardsServer { public static MessageForwardsRpcInterface handler; @SuppressWarnings("rawtypes") public static MessageForwardsService.Processor processor; public static void start() { try { System.out.println("async TNonblockingServer start ...."); final TProcessor tprocessor = new MessageForwardsService.Processor<MessageForwardsService.Iface>( new MessageForwardsRpcInterface()); Runnable simple = new Runnable() { public void run() { simple(tprocessor); } }; new Thread(simple).start(); } catch (Exception e) { System.out.println("Server start error!!!"); e.printStackTrace(); } }// /**// * RPC 服务端// * @param processor// */ public static void simple(TProcessor tprocessor) { TNonblockingServerSocket tnbSocketTransport; try { tnbSocketTransport = new TNonblockingServerSocket(9090); TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args( tnbSocketTransport); tnbArgs.processor(tprocessor); tnbArgs.transportFactory(new TFramedTransport.Factory()); tnbArgs.protocolFactory(new TCompactProtocol.Factory()); // 使用非阻塞式IO,服务端和客户端需要指定TFramedTransport数据传输的方式 TServer server = new TNonblockingServer(tnbArgs); server.serve(); } catch (TTransportException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
客户端
public class ControlCommand { public static void main( String[] args ) { test("192.168.1.3"); } public static void test(String ip){ TTransport transport = null; try { transport = new TFramedTransport(new TSocket(ip,9090, 3000)); // 协议要和服务端一致 TProtocol protocol = new TCompactProtocol(transport); MessageForwardsService.Client client = new MessageForwardsService.Client( protocol); transport.open(); String result = client.getAllChannels(); System.out.println("Thrify client result =: " + result); transport.close(); } catch (TTransportException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } finally { if (null != transport) { transport.close(); } } }}
阅读全文
0 0
- thrift异步调用
- Thrift 异步调用
- Thrift 技术文档-异步调用
- thrift java多线程非阻塞同步/异步调用实例
- Thrift双向异步远程调用(外文翻译)学习第一步
- Thrift 半同步半异步的服务模型-THsHaServer(异步调用客户端)
- thrift远程调用示例
- thrift远程调用示例
- 初探Thrift客户端异步模式
- RPC 工具 --Thrift(二) Thrift 异步模式
- Thrift学习(OC的调用)
- scala远程调用thrift接口
- Thrift服务搭建和调用
- thrift源码研究-异步client&server
- thrift-异步client&server使用例子
- Thrift异步IO服务器源码分析
- Thrift异步IO服务器源码分析
- thrift-client异步+server非阻塞
- Spark算子[02]:coalesce,repartition
- 如何利用物联网阻止偷猎动物
- tensorflow中模型无法保存出现 get NotFoundError
- 基于TCP通信协议的异步实现
- opencv实现双边滤波 + 锐化
- Thrift 异步调用
- ssm框架创建简单的DVD管理系统(一)项目简介
- JNDI 是什么
- Office之OneNote—1.快捷键操作
- CSS3轻松实现彩色旋转六面体动画
- apache jmeter设置HEAP大小
- 第八章:用通配符进行过滤
- MVP进行简单粗爆的封装
- spring-redis缓存方案学习三:基于aop的自定义注解开发