简体   繁体   English

基于Netty的非阻塞REST框架

[英]Netty based non-blocking REST framework

I am working on a RESTfull application which requires high scalability. 我正在开发一个需要高可伸缩性的RESTfull应用程序。 I am considering Netty based frameworks for RESTfull applications. 我正在考虑基于Netty的RESTfull应用程序框架。 I went through some of the available options and tried to get what they can offer as a non-blocking implementation. 我浏览了一些可用的选项,并尝试将它们作为非阻塞实现提供。 Here are my findings: 以下是我的发现:

  1. rest.li --> Still under experimental phase for Netty based NIO implementaions. rest.li - >仍处于基于Netty的NIO实施的试验阶段。 So, not production ready. 所以,不准备生产。
  2. RESTEasy --> Standard JBoss project which supports Netty 4.x. RESTEasy - >支持Netty 4.x的标准JBoss项目。 But,instead of full stack Netty based NIO implementation, RESTEasy is a Buffer exchange between Netty and RESTEasy. 但是,RESTEasy不是基于Netty的完整堆栈NIO实现,而是Netty和RESTEasy之间的缓冲交换。 It's not taking the advantages of Netty. 它没有利用Netty的优势。 Therefore scalability is not as high as expected from a Netty based framework. 因此,可扩展性不如基于Netty的框架所预期的那么高。
  3. Netty-http component --> Another option is Apache Camel integration while using Netty-http component as an endpoint for routing requests to services exposed in from of beans. Netty-http组件 - >另一个选项是Apache Camel集成,同时使用Netty-http组件作为端点,用于将请求路由到bean中公开的服务。 I think it's same as RESTEasy, only Netty-http component uses Netty based NIO capabilities and the rest of the system would use the old IO. 我认为它与RESTEasy相同,只有Netty-http组件使用基于Netty的NIO功能,而系统的其余部分将使用旧的IO。 I don't think I would help much in gaining scalabiltiy. 我不认为我会在获得scalabiltiy方面帮助太大。
  4. RESTExpress --> It claims to be Netty based framework for RESTFull application. RESTExpress - >它声称是基于Netty的RESTFull应用程序框架。 But, neither it has a decent community nor it can be trusted (Because it's very new) for enterprise application which requires high degree of security. 但是,对于需要高度安全性的企业应用程序而言,它既没有一个像样的社区,也没有可信任(因为它是非常新的)。

Before having the above findings, I wanted to use some ready to use framework and get the work done faster. 在得到上述发现之前,我想使用一些随时可用的框架并更快地完成工作。

I know it's an opinion based question. 我知道这是一个基于意见的问题。 But, still I seriously need help for choosing right framework for my application. 但是,我仍然非常需要帮助为我的应用程序选择正确的框架。 If in case, there is no Netty based REST framework: would it be wise to go for plumbing low level Netty based NIO code in my application? 如果以防万一,没有基于Netty的REST框架:在我的应用程序中使用基于Netty的低级NIO代码是否明智? Any help appreciated. 任何帮助赞赏。 Thanks in advance. 提前致谢。

If you really want non-blocking you need to do non-blocking from the ground up and have proper REST clients . 如果你真的想要非阻塞,你需要从头开始进行非阻塞,并拥有适当的REST客户端 Otherwise as stated in my comment the performance difference will be negligible and in many cases worse for NIO (Netty with thread sharing). 否则,如我的评论中所述,性能差异可以忽略不计,并且在许多情况下NIO(带线程共享的Netty)更糟糕。

There only two libraries that I know do non-blocking from the ground up Vert.x and somewhat Finagle (its missing other things like non-blocking data access). 我知道只有两个库从头开始进行非阻塞Vert.x和一些Finagle (它缺少其他东西,如非阻塞数据访问)。

You should also know Tomcat and various other servlet containers that can work with JAX-RS support NIO. 您还应该了解可以使用JAX-RS支持NIO的Tomcat和其他各种servlet容器。 The issue is that even though NIO is supported it will still be a single thread per request. 问题是,即使支持NIO,它仍然是每个请求的单个线程。 Only Play, Finagle, Vert.x and pure Netty (regardless of NIO) support a different shared threading model and thus have different mechanisms for doing concurrency. 只有Play,Finagle,Vert.x和纯Netty(不管NIO)支持不同的共享线程模型,因此具有不同的并发机制。

Here's the list of microframeworks I'm aware of for REST applications: 这是我知道的REST应用程序的微框架列表:

Please feel free to comment to the answer - I'll update the answer to add more. 请随时评论答案 - 我会更新答案以添加更多内容。

Have you taken a look at Play ? 你看过Play吗?

It appears that you are inclined to use Netty but if you are willing to look around a very simple Grizzly + Jersey setup will probably perform well enough. 看来你倾向于使用Netty但是如果你愿意环顾一下非常简单的Grizzly + Jersey设置可能会表现得很好。 Heck, a simple Glassfish 4.0 JAX-RS app may work well too. 哎呀,一个简单的Glassfish 4.0 JAX-RS应用程序也可以运行得很好。

You can take a look at AsyncRestTemplate in Spring Framework 4.2.5.RELEASE. 您可以在Spring Framework 4.2.5.RELEASE中查看AsyncRestTemplate It can be used on top of Netty. 它可以在Netty之上使用。

Note: by default AsyncRestTemplate relies on standard JDK facilities to establish HTTP connections. 注意:默认情况下,AsyncRestTemplate依赖于标准JDK工具来建立HTTP连接。 You can switch to use a different HTTP library such as Apache HttpComponents, Netty, and OkHttp by using a constructor accepting an AsyncClientHttpRequestFactory. 您可以通过使用接受AsyncClientHttpRequestFactory的构造函数切换到使用不同的HTTP库,例如Apache HttpComponents,Netty和OkHttp。

There is one more framework which uses Netty and RxJava, It's called datamill 还有一个框架使用Netty和RxJava,它叫做datamill

If you are interested in building web applications using a functional reactive style then should consider it. 如果您对使用功能性反应式风格构建Web应用程序感兴趣,那么应该考虑它。

Spring 5 comes with a reactive web framework called WebFlux. Spring 5附带了一个名为WebFlux的反应式Web框架。 You can choose from multiple servers like Netty or Undertow. 您可以选择Netty或Undertow等多个服务器。 A reactive non-blocking WebClient has also been added to Spring and it also has support for reactive Mongo, Redis and Cassandra (I guess more is coming soon). 一个反应性非阻塞WebClient也被添加到Spring,它也支持反应性Mongo,Redis和Cassandra(我想更多即将推出)。

Spring Boot, the 'opinionated view of Spring', will also get a new version (2.0) based on Spring 5. At the time of writing it is expected to be released in February. 春天的引导,“春天的观点”,也将获得基于Spring 5的新版本(2.0)。在撰写本文时,它预计将在2月份发布。

More information on the reactive stack of Spring: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html 有关Spring的反应堆栈的更多信息: https//docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html

Undertow 3.0 will be on the top of Netty (instead of XNIO) . Undertow 3.0将成为Netty(而不是XNIO)的首选 A perfect, super light, simple API to build an application like REST API server. 一个完美,超轻,简单的API,用于构建REST API服务器之类的应用程序。 I use it for almost any Java Microservices I have. 我几乎用于任何Java微服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM