简体   繁体   English

Web Services vs EJB vs RMI,优缺点?

[英]Web Services vs EJB vs RMI, advantages and disadvantages?

My web server would be overloaded quickly if all the work were done there. 如果在那里完成所有工作,我的Web服务器将很快超载。 I'm going to stand up a second server behind it, to process data. 我要站在它后面的第二台服务器来处理数据。

What's the advantage of EJB over RMI, or vice versa? EJB相对于RMI有什么优势,反之亦然?

What about web services (SOAP, REST)? 那么Web服务(SOAP,REST)呢?

EJBs are built on top of RMI. EJB建立在RMI之上。 Both imply Java clients and beans. 两者都暗示Java客户端和bean。 If your clients need to be written in something else (eg, .NET, PHP, etc.) go with web services or something else that speaks a platform-agnostic wire protocol, like HTTP or XML over HTTP or SOAP. 如果您的客户需要用其他东西编写(例如,.NET,PHP等),请使用Web服务或其他与平台无关的有线协议,如HTTP或XML over HTTP或SOAP。

If you choose RMI, you don't need a Java EE EJB app server. 如果选择RMI,则不需要Java EE EJB应用程序服务器。 You have to keep client and server JVMs in synch; 您必须保持客户端和服务器JVM同步; you can't upgrade the client without upgrading the server. 如果不升级服务器,则无法升级客户端。 You have to write all the services that the EJB app server provides for you (eg, connection pooling, naming and directory services, pooling, request queuing, transactions, etc.). 您必须编写EJB应用服务器为您提供的所有服务(例如,连接池,命名和目录服务,池,请求排队,事务等)。

RMI is quite low level when you think about it. 当你想到它时,RMI是非常低的水平。 Why would you drop all the way back to CORBA? 你为什么要一直回到CORBA?

A better choice is EJB 3.0 versus Spring. 更好的选择是EJB 3.0与Spring。 It depends on whether you like POJO development, want a choice of relational technologies besides ORM and JPA, among other things. 这取决于你是否喜欢POJO开发,除了其他方面之外还需要选择除ORM和JPA之外的关系技术。

You can pay for a Java EE app server (eg, WebLogic, WebSphere) or use an open source one (JBOSS, Glassfish and OpenEJB and ActiveMQ), or you can stick to Spring and deploy on Tomcat, Jetty, Resin or any other servlet/JSP engine. 您可以为Java EE应用服务器(例如,WebLogic,WebSphere)付费或使用开源源服务器(JBOSS,Glassfish和OpenEJB以及ActiveMQ),或者您可以坚持使用Spring并在Tomcat,Jetty,Resin或任何其他servlet上部署/ JSP引擎。

Spring offers a lot of choice by being technology agnostic: persistence (Hibernate, iBatis, JDBC, JDO, JPA, TopLink), remoting (HTTP, Hessian, Burlap, RMI, SOAP web service), etc. Spring通过技术不可知提供了很多选择:持久性(Hibernate,iBatis,JDBC,JDO,JPA,TopLink),远程处理(HTTP,Hessian,Burlap,RMI,SOAP Web服务)等。

EJB 3.0 is a spec with many vendors; EJB 3.0是许多供应商的规范; Spring can only be had from Spring Source. Spring只能来自Spring Source。

I would recommend Spring . 我会推荐Spring It's very solid, has lots of traction, isn't going anywhere. 它非常坚固,有很多牵引力,不会去任何地方。 It leaves all your options open. 它会打开您的所有选项。

Web services are great in theory, but there are some gotchas that you need to watch out for: Web服务在理论上很棒,但是有一些问题需要注意:

  1. Latency. 潜伏。 Fowler's first law of distributed objects: "Don't!" 福勒的第一个分布式对象定律:“不要!” An architecture consisting of lots of fine-grained distributed SOAP services will be elegant, beautiful, and slow as molasses. 由许多细粒度分布式SOAP服务组成的体系结构将像糖蜜一样优雅,美观和缓慢。 Think carefully before distributing. 分发之前要仔细考虑。
  2. Marshalling from XML to objects and back consumes CPU cycles that aren't providing any business value besides allowing your clients to speak a platform-agnostic protocol. 从XML到对象和后端的编组会消耗CPU周期,除了允许客户端使用与平台无关的协议之外,它们不提供任何业务价值。
  3. SOAP is a standard that is becoming more bloated and complex every day, but it has lots of tool support. SOAP是一种日常变得越来越臃肿和复杂的标准,但它有很多工具支持。 Vendors like it because it helps drive sales of ESBs. 供应商喜欢它,因为它有助于推动ESB的销售。 REST is simple but not as well understood. REST很简单但不太清楚。 It's not supported by tools. 工具不支持它。

Spring's web service module is very good, but do be careful about choosing to deploy this way. Spring的Web服务模块非常好,但是选择以这种方式部署时要小心。 Write in terms of POJO service interfaces. 根据POJO服务接口写。 These will allow you to get the conceptual isolation you want, defer the deployment choice until the last moment, and let you change your mind if the first thought doesn't perform well. 这些将允许您获得所需的概念隔离,将部署选择推迟到最后一刻,并且如果第一个想法不能很好地让您改变主意。

Between EJB and RMI, EJB would certainly be better - it has everything RMI has and much more via the container (object pooling, transaction management, etc.) 在EJB和RMI之间,EJB肯定会更好 - 它拥有RMI所拥有的一切以及更多通过容器(对象池,事务管理等)

Between EJB and web services, web services would give you more portability if you want to be able to call them from non-java apps in the future. 在EJB和Web服务之间,如果您希望将来能够从非Java应用程序调用它们,Web服务将为您提供更多可移植性。 EJB again gives you things like transaction management and pooling that you might not get "out of the box" with web services. EJB再次为您提供了事务管理和池化等功能,您可能无法通过Web服务“开箱即用”。

Personally, if I were doing it, I would probably use EJB or some similar remote object framework (spring remoting comes to mind as well). 就个人而言,如果我这样做,我可能会使用EJB或类似的远程对象框架(也会想到spring remoting)。 If you need the ability to call the objects from a non-java app, you can always front your EJBs with simple web service proxies as needed. 如果您需要能够从非Java应用程序调用对象,则可以根据需要随时使用简单的Web服务代理来使用EJB。

Re: web services (SOAP, REST) If your back end servers are not going to be exposed publicly, then you are not getting any benefit from using platform independent web service interfaces such as SOAP/REST. Re:Web服务(SOAP,REST)如果您的后端服务器不会公开公开,那么使用平台无关的Web服务接口(如SOAP / REST)就无法获得任何好处。
In fact you'll be incurring a penalty with all of the overhead added by the XML tags wrapping the data across a remote call, not to mention the hit you'll take from marshalling and unmarshalling the XML to java objects. 事实上,你会因为在远程调用中包装数据的XML标记所增加的所有开销而受到惩罚,更不用说你将从编组和解组XML到java对象的命中。
Although any distributed call is going to require some level of serialization - even RMI/EJB, but the price is greater when serializing to human readable XML. 虽然任何分布式呼叫将需要系列化的一些水平 - 甚至RMI / EJB,但序列化到人类可读的XML当时的价格是较大的。

You may not need to code remote calls in java at all, you could front your service with a plain apache httpd instance, which is configured to load balance across multiple java servers using mod_jk or mod_proxy . 您可能根本不需要在java中编写远程调用的代码,您可以使用普通的apache httpd实例来处理您的服务,该实例配置为使用mod_jkmod_proxy在多个Java服务器之间进行负载平衡。
These modules can be used to load balance across servlet containers such as tomcat/jetty, or ejb containers such as jboss/glassfish. 这些模块可以用来加载跨servlet容器如Tomcat /码头,或EJB容器例如JBoss / glassfish的平衡。

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

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