HelloService.thrift 定义服务接口

namespace java com.example.thriftservice HelloService {string hello(1:string name)
}

使用thrift-0.9.3.exe 工具,命令:thrift-0.9.3 -r --gen java HelloService.thrift 在当前文件夹gen-java 下面生成HelloService.java

public class HelloService {public interface Iface {public String hello(String name) throws org.apache.thrift.TException;}public interface AsyncIface {public void hello(String name, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;}
}

在这里使用thrift 规范,生成同步Iface 和异步AsyncIface 接口。

HelloServiceIfaceImpl 实现同步接口。

public class HelloServiceIfaceImpl implements HelloService.Iface
{@Overridepublic String hello(String name) throws TException{System.out.println("ArmeriaClient ----->"+name);return "hello to "+name;}
}

ArmeriaServer 为RPC 端服务类:

public class ArmeriaServer
{public static void main(String[] args){HelloService.Iface helloHandler = new HelloServiceIfaceImpl();//we created a new ServerBuilder and added a new ThriftService to it.ServerBuilder sb = new ServerBuilder();sb.port(8080, SessionProtocol.HTTP);//The ThriftService is bound at the path /hello and will use the TBinary format.//We also decorated the ThriftService using LoggingService, which logs all Thrift calls and replies.sb.serviceAt("/hello",ThriftService.of(helloHandler, SerializationFormat.THRIFT_BINARY).decorate(LoggingService::new)//使用日志输出请求数据和响应数据).serviceUnder("/docs/", new DocService());//Armeria provides a service called DocService, which discovers all ThriftService in your Armeria server and lets you browse the available service operations and structs:Server server= sb.build();server.start();System.out.println("ArmeriaServer  start");}
}

ArmeriaClient 为RPC客户端类:

public class ArmeriaClient
{public static void main(String[] args) throws TException{HelloService.Iface helloService = new ClientBuilder("tbinary+http://127.0.0.1:8080/hello").responseTimeoutMillis(10000).decorator(LoggingClient::new).build(HelloService.Iface.class); String greeting = helloService.hello("Armerian World");System.out.println("ArmeriaClient:"+greeting);}
}

ArmeriaServer RPC服务端 增加数据分析、日志、文档。

public class ArmeriaServer
{public static void main(String[] args){MetricRegistry metricRegistry = new MetricRegistry();ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();reporter.start(1, TimeUnit.SECONDS);HelloService.Iface helloHandler = new HelloServiceIfaceImpl();//we created a new ServerBuilder and added a new ThriftService to it.ServerBuilder sb = new ServerBuilder();sb.port(8080, SessionProtocol.HTTP);//The ThriftService is bound at the path /hello and will use the TBinary format.//We also decorated the ThriftService using LoggingService, which logs all Thrift calls and replies.sb.serviceAt("/hello",ThriftService.of(helloHandler, SerializationFormat.THRIFT_BINARY).decorate(LoggingService::new).decorate(MetricCollectingService.newDropwizardDecorator(metricRegistry, MetricRegistry.name("client", "HelloService")))//使用日志输出请求数据和响应数据).serviceUnder("/docs/", new DocService());//Armeria provides a service called DocService, which discovers all ThriftService in your Armeria server and lets you browse the available service operations and structs:Server server= sb.build();server.start();System.out.println("ArmeriaServer  start");}
}

Armeria 小试牛刀相关推荐

  1. Node.js开发WEB项目后端接口API,基于mysql5.7数据库(小试牛刀)

    项目结构 main.js(入口文件,开启9999端口监听,实现RESTful风格接口访问) const express = require("express"); const ap ...

  2. mongoose小试牛刀

    参考: Mongoose Networking Library Documentation 正文: 先展示一下小试牛刀的结果吧- 一. 首先在程序默认指定的端口上开启服务,在后台运行 ./http_c ...

  3. CSS学习18之小试牛刀

    小试牛刀 到现在为止,我们已经将css要学习的初级中级高级知识都已经学完了,接下来我们就应该对自己做一个小测验了,以下就是我的小测验,模拟qq会员官网的头部栏! 素材 bg.png背景图 logo.p ...

  4. Android开发之Retrofit小试牛刀

    感觉好久没有写Android的文章了,囧囧囧!因为Retrofit实在是太火了, 火得我一直跃跃欲试,但是由于种种原因吧,一直都没有用过.周末闲来无事,利用一个以前开发中用过的服务器API来小试牛刀一 ...

  5. MongoDB 小试牛刀

    MongoDb是不错的NoSQL数据库之一,NoSQL 的意思是Not Only SQL,比关系型数据库MySQL.SQL Server等更易于扩展,更多的应用于海量数据的存储,且数据可以弹性跨LAN ...

  6. 深度学习和目标检测系列教程 2-300:小试牛刀,使用 ImageAI 进行对象检测

    @Author:Runsen 对象检测是一种属于更广泛的计算机视觉领域的技术.它处理识别和跟踪图像和视频中存在的对象.目标检测有多种应用,如人脸检测.车辆检测.行人计数.自动驾驶汽车.安全系统等.Im ...

  7. C#位图BitArray 小试牛刀

    前面聊了布隆过滤器,回归认识一下位图BitMap,阅读前文的同学应该发现了布隆过滤器本身就是基于位图,是位图的一种改进. 难缠的布隆过滤器,这次终于通透了 位图 先看一个问题, 假如有1千万个整数,整 ...

  8. 05.SQL Server大数据群集小试牛刀--HDFS查询

    05.SQL Server大数据群集小试牛刀--HDFS查询 SQL Server大数据群集查询HDFS ,利用之前创建好的大数据群集,使用官方提供的测试数据进行测试.脚本是官方的脚本,要知道干了什么 ...

  9. Jenkins持续集成之小试牛刀

    关于Jenkins的安装,大家可以参考我的这两篇文章: Ubuntu16.04环境安装jenkins docker安装jenkins及其相关问题解决 之前没有好好研究过Jenkins,只是简单学会怎么 ...

最新文章

  1. 安卓模拟器BlueStacks 安装使用教程(图解)
  2. Matlab和Python(Numpy,Scipy)与Lapack的关系
  3. 第十二章 支持向量机-机器学习老师板书-斯坦福吴恩达教授
  4. JVM调优-GC参数
  5. 彻底卸载MYSQL,windows版
  6. java使用poi.xssf 写入内容到excel表格中 和 读取 表格里面的数据
  7. PAT (Basic Level) Practice1013 数素数
  8. 容器就业市场持续增长,5条建议让您快速掌握Docker技能
  9. 高数篇(三)-- 最小二乘法、正则化
  10. 华三交换机snmp配置
  11. 最简单DIY基于ESP32CAM的物联网相机系统③(在JSP服务器图传相片给所有客户端欣赏)
  12. MyEclipse在启动了诸如Tomcat等web服务后,控制台信息不显示的问题
  13. 如何关闭服务器系统防火墙设置方法,怎么关闭防火墙 Windows自带防火墙关闭方法...
  14. Python 重载向量加法运算符 +
  15. 网络基础 select模型
  16. php刷网站关键词排名,网站关键词排名如何刷点击流量?
  17. 云创办公智慧企业丨企业的下一个前沿阵地
  18. F4—LVDS接口LCD显示彩图测试-2023-02-25
  19. 非对称加密和对称加密
  20. js 或者vue中for循环去掉最后一个逗号

热门文章

  1. 尚硅谷-宋红康-MySQL高级性能篇
  2. 解决win10使用Fiddler4无法手机抓包的问题(真正的大招!)
  3. android水波纹动画制作,Framer之事件 | 如何制作安卓点击水波纹效果?
  4. Selenium使用浏览器自动登录校园网
  5. WAF——web安全及web应用防火墙
  6. 准双向口、推挽输出、开漏输出、高阻输入的区别
  7. 013 gtsam/examples/ISAM2Example_SmartFactor.cpp
  8. 7.Python条件语句之if语句——从入门到实践
  9. 代码敲累了就来看看《PPT制作经验分享-发布版PPT》
  10. 【Axure基础教程】第17张 设置不透明度