三合一车轮?RestyPass,HTTP调用客户端库
来源:互联网 发布:军犬网络舆情监控系统 编辑:程序博客网 时间:2024/04/29 20:53
RestyPass
高性能的Restful服务调用客户端库,完全兼容Spring MVC 注解,基于接口和注解自动代理客户端HTTP请求,支持服务发现,负载均衡,自动熔断,降级,重试,限流。覆盖Feign + Hystrix + Ribbon + ApacheHttpClient的功能
对比SpringCloud技术栈:Feign+Hystrix+Ribbon+ApacheHttpClient
- Http连接池性能提升,RestyPass采用基于Netty实现的AsyncHttpClient连接池,性能测试比ApacheHttpClient高30%。
- 减少对象生成,Feign+Hystrix+Ribbon+ApacheHttpClient,多个库组合完成一个完整的http客户端调用请求,一个调用链中创建很多多余对象。
- 减少线程切换,如Hystrix,ApacheHttpClient中都有自己的线程池,一个请求的完成往往要经过多次的线程切换,损耗性能。
- 更易配置,RestyPass使用注解的方式配置各个接口请求;而使用Feign+Hystrix+Ribbon+ApacheHttpClient,则面临每个库都有自己的配置项,配置繁多而且容易发生冲突,亲身实践,想把这一套配置好是一件不容易的事情。
- 实时更新配置,RestyPass支持实时更新部分配置,比如实时关闭/启用降级服务,实时熔断/恢复服务,且粒度可以精确到接口级。
- 易开发,可自由开发大部分核心接口的自定义实现,并直接注入即可启用(Spring容器)。
- 支持过滤器,并可以自定义过滤器并注入
- 支持限流
示例(demo[调用方]+demo-serverside[服务端])
- 客户端
// 使用@EnableRestyPass注解启用RestyPass@SpringBootApplication@EnableRestyPass(basePackages = {"com.github.df"})@RestController//@EnableDiscoveryClient//启用spring cloud 服务发现则RestyPass自动使用spring的服务发现方式,// 否则默认读取resty-server.yaml来获取服务实例// 可自定义其它发现服务的方式,实现ServerContext接口并注入即可public class TestClientApplication { public static void main(String[] args) { SpringApplication.run(TestClientApplication.class, args); } @Autowired private ProxyService proxyService; @RequestMapping(value = "nothing") public String callNothing() { proxyService.getNothing(); return "OK"; }}//使用接口和注解定义并配置调用客户端//RestyService注解定义服务@RestyService(serviceName = "server", fallbackEnabled = true, fallbackClass = ProxyServiceImpl.class, forceBreakEnabled = false, circuitBreakEnabled = false, loadBalancer = RandomLoadBalancer.NAME, retry = 1, requestTimeout = 10000, limit = 1000 //限流)@RequestMapping(value = "/resty")public interface ProxyService extends ApplicationService { // RestyMethod注解定义服务接口 @RestyMethod(retry = 2, forceBreakEnabled = "true", limit = 10) @RequestMapping(value = "/get_nothing", method = RequestMethod.GET, headers = "Client=RestyProxy", params = "Param1=val1") void getNothing();}
# resty-server.yamlservers: - serviceName: server instances: - host: localhost port: 9201 - host: localhost port: 9202
- 服务端
@RestController@RequestMapping("/resty")public class TestController { @RequestMapping(value = "/get_nothing", method = RequestMethod.GET) public void nothing() { System.out.println("############nothing"); } }
项目地址
项目 Github地址(主): https://github.com/darren-fu/RestyPass
码云地址: https://gitee.com/darren-fu/RestyPass
(已完成第一版本,持续演进中…)
阅读全文
0 0
- 三合一车轮?RestyPass,HTTP调用客户端库
- HTTP接口客户端调用程序
- Poco库http客户端代码
- HTTP/FTP客户端开发库
- HTTP/FTP客户端开发库
- webservice和http请求的 客户端调用代码
- 选好”车轮”
- http客户端
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- linux下HTTP/FTP客户端开发库
- JavaScript HTTP客户端库axios介绍
- libcurl库进行http通讯-基于 C 的 HTTP 客户端
- WebService应用之客户端 Ksoap 库调用
- http调用
- 聊聊 React Router v4 的设计思想
- git push时出现错误refusing to update checked out branch: refs/heads/master
- Google算法题:寻找中位数
- JDBC
- BOM基础一
- 三合一车轮?RestyPass,HTTP调用客户端库
- 利用Sqoop从oracle同步数据到HDFS出现The Network Adapter could not establish the connection的解决方法
- 【PAT】【Advanced Level】1050. String Subtraction (20)
- MongoDB主从复制,副本集, Sharding
- 解决fatal: No remote repository specified. Please, specify either a URL...
- 欢迎使用CSDN-markdown编辑器
- mysql主从复制实践
- Day43-Struts02
- git manual