Nifty thrift服务端和客户端实现

开源网站开源项目 24-04-05 15:45:37

Nifty是facebook公司开源的,基于netty的thrift服务端和客户端实现。

然后使用此包就可以快速发布出基于netty的高效的服务端和客户端代码。

示例:

public void startServer() {    // Create the handler    MyService.Iface serviceInterface = new MyServiceHandler();    // Create the processor    TProcessor processor = new MyService.Processor<>(serviceInterface);    // Build the server definition    ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)                                                            .build();    // Create the server transport    final NettyServerTransport server = new NettyServerTransport(serverDef,                                                                 new NettyConfigBuilder(),                                                                 new DefaultChannelGroup(),                                                                 new HashedWheelTimer());    // Create netty boss and executor thread pools    ExecutorService bossExecutor = Executors.newCachedThreadPool();    ExecutorService workerExecutor = Executors.newCachedThreadPool();    // Start the server    server.start(bossExecutor, workerExecutor);    // Arrange to stop the server at shutdown    Runtime.getRuntime().addShutdownHook(new Thread() {        @Override        public void run() {            try {                server.stop();            } catch (InterruptedException e) {                Thread.currentThread().interrupt();            }        }    });}

Or the same thing using guice:

public void startGuiceServer() {    final NiftyBootstrap bootstrap = Guice.createInjector(        Stage.PRODUCTION,        new NiftyModule() {            @Override            protected void configureNifty() {                // Create the handler                MyService.Iface serviceInterface = new MyServiceHandler();                // Create the processor                TProcessor processor = new MyService.Processor<>(serviceInterface);                // Build the server definition                ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)                                                                        .build();                // Bind the definition                bind().toInstance(serverDef);            }        }).getInstance(NiftyBootstrap.class);    // Start the server    bootstrap.start();    // Arrange to stop the server at shutdown    Runtime.getRuntime().addShutdownHook(new Thread() {        @Override        public void run() {            bootstrap.stop();        }    });}
[Nifty thrift服务端和客户端实现]相关推荐
Asunder 音频 CD 提取工具

Asunder 音频 CD 提取工具

Asunder 是一款图形化的音频 CD 提取工具。你可以使用它将 CD 中的音轨以 WAV、MP3、OGG、FLAC 等格式保……...

mui 移动HTML5前端框架

mui 移动HTML5前端框架

性能和体验的差距,一直是mobile app开发者放弃HTML5的首要原因。 浏览器天生的切页白屏、不忍直视的转页……...

Min Browser 开源的极简浏览器

Min Browser 开源的极简浏览器

Min是一款开源的极简浏览器,拥有智能、快速的特点。一些特性: 通过使用DuckDuckGo在搜索栏中显示搜索结……...

TODS 自动化机器学习系统

TODS是一个全栈的自动化机器学习系统,主要针对多变量时间序列数据的异常检测。 TODS 提供了详尽的用于构……...

QCAD CAD 应用程序

QCAD CAD 应用程序

QCad 是一个专业的 CAD 系统。QCad 使用户能够创建技术图纸,如计划、建筑、室内装饰、机械部件或架构和……...

今日开源
  1. OpenCart 开源电子商务系统

    OpenCart 开源电子商务系统

    OpenCart是新一代基于PHP开发的开源在线购物车系统。OpenCart具有易于使用,功能丰富,搜索引擎友好和漂亮简洁的操作界面等特点。 演示地址:https://www.opencart.com/index.php?route=cms/demo

    开源软件 2024-05-04

  2. Hound 快速代码搜索引擎

    Hound 快速代码搜索引擎

    Hound 是轻量级的快速代码搜索工具。Hound 是极其快速的源代码搜索引擎。Hound 的核心是基于这篇文章和代码的,作者是 Russ Cox:Regular Expression Matching with a Trigram Index。Hound 自身是个静态 React 前……

    开源软件 2024-05-04

  3. Codis Redis 集群解决方案

    Codis Redis 集群解决方案

    Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的……

    开源软件 2024-05-04

返回顶部小火箭