简体   繁体   English

在实现Web服务(SOA / REST)时,使用RMI实现EJB仍然有用吗?

[英]Is still useful to implement EJB with RMI when you can implement Web Services (SOA/REST)?

This might sound similar to this , but it's not. 这可能听起来与类似,但事实并非如此。

I kind of understand EJB and RMI, and I have been working with web services under SOA for a while. 我有点理解EJB和RMI,而且我已经在SOA下使用Web服务了一段时间。 I want to know why is useful to work using EJB exposing remote interfaces under RMI instead of publishing Web Services (SOA/REST, but mostly SOA). 我想知道为什么使用EJB暴露RMI下的远程接口而不是发布Web服务(SOA / REST,但主要是SOA)是有用的。 I'm not asking which one is better, just I want to know a very good reason of why should I prefer to implement EJB with remote interfaces over Web Services. 我不是在问哪一个更好,只是我想知道为什么我更喜欢通过Web服务实现带有远程接口的EJB的一个很好的理由。

I have reviewed a lot of webpages but all seemed outdated. 我查看了很多网页,但似乎都过时了。 Until now, what I have is that EJB exposing remote interfaces is only better than WS when integrating with Java legacy system. 到目前为止,我所拥有的是,在与Java遗留系统集成时,暴露远程接口的EJB仅比WS更好。 If I want to manage transactions I could implement EJB with local interfaces. 如果我想管理事务,我可以使用本地接口实现EJB。 Also I don't think choosing EJB over RMI is more efficient than a Web Service interface. 另外,我不认为选择EJB over RMI比Web Service接口更有效。

Am I right? 我对吗? Is there something I'm missing? 有什么我想念的吗?

Really thanks in advance. 非常感谢提前。

EJBs are better if 如果是,EJB更好

  • you need to perform number of calls which should be done in one transaction (in theory we have transactional web services, but not every implementation provides them), (stateful) EJBs shine when it comes to transaction management. 你需要执行一些应该在一个事务中完成的调用(理论上我们有事务Web服务,但不是每个实现都提供它们),(有状态的)EJB在事务管理方面都很闪耀。 Almost anytime you need statefulness EJB would be better then Web Service; 几乎任何时候你需要有状态EJB比Web服务更好;
  • you need performence - Web Services are slow - they use XML/JSON pushed through HTTP, RMI over IIOP protocol used by EJB is way more efficient; 你需要表现 - Web服务很慢 - 他们使用通过HTTP推送的XML / JSON,而EJB使用的IIOP协议上的RMI更有效率;
  • you need to connect to some legacy system which uses outdated spec for Java Web Services (ugly Axis 1.0 stuff, not compatible with JAX-WS) it can be a nightmare to connect everything with web services, deal with not compatible WSDL definitions, strange SOAP envelopes. 你需要连接到一些遗留系统,它使用过时的Java Web Services规范(丑陋的Axis 1.0的东西,与JAX-WS不兼容),将所有内容与Web服务连接,处理不兼容的WSDL定义,奇怪的SOAP可能是一场噩梦信封。 EJBs are backward compatible, old EJB 2 could be connected without any problem with EJB 3.1; EJB是向后兼容的,旧的EJB 2可以在没有EJB 3.1的任何问题的情况下连接;
  • modern EJBs (EJB 3.X) can expose their interface as a JAX-WS SOAP/WSDL service or JAX-RS REST service by adding two or three simple annotations 现代EJB(EJB 3.X)可以通过添加两个或三个简单注释将其接口公开为JAX-WS SOAP / WSDL服务或JAX-RS REST服务

Why (REST) Web services are so popular then? 为什么(REST)Web服务如此受欢迎? EJBs can be connected only to another Java application. EJB只能连接到另一个Java应用程序。 Majority of modern Rich Internet Applications are written in JavaScript, so the only way to connect them with any backend is to use some kind of web service (usually REST + JSON). 大多数现代富Internet应用程序都是用JavaScript编写的,因此将它们与任何后端连接的唯一方法是使用某种Web服务(通常是REST + JSON)。 For such applications EJBs are pretty useless. 对于这样的应用程序,EJB很没用。

Both the client and service must be written in Java if you use RMI as the wire protocol. 如果使用RMI作为有线协议,则必须使用Java编写客户端和服务。

SOAP uses XML over HTTP, and REST uses pure HTTP for communication between client and service. SOAP使用XML over HTTP,而REST使用纯HTTP进行客户端和服务之间的通信。 Either end of the conversation can be written in any language that can send appropriate requests over HTTP, which is far less restrictive. 对话的任何一端都可以用任何可以通过HTTP发送适当请求的语言编写,这种限制要少得多。

I think this is one reason why web services over HTTP have won out over RMI. 我认为这是HTTP上的Web服务胜过RMI的一个原因。 Simple and open win, every time. 每次都是简单而开放的胜利。

They are different things for different purposes. 它们是用于不同目的的不同东西。

EJBs are for use within an N -tier system that is tightly coupled and you are in control of all elements. EJB用于紧密耦合的N层系统,您可以控制所有元素。 They offer direct coding in the language using what appear to be ordinary method calls, and LAN-type performance over IIOP or whatever other protocol the EE vendor has deployed. 它们使用看似普通的方法调用,以及IIOP上的LAN类型性能或EE供应商已部署的任何其他协议,提供语言的直接编码。

SOAP/REST is best for use across the Internet, or in B2B or other situations where you aren't in control of both ends and you need loose coupling. SOAP / REST最适合在Internet上使用,或者在B2B或其他无法控制两端且需要松散耦合的情况下使用。 You get much slower performance due to all the XML, but you also get an industry standard protocol in the middle which gives both ends protection against single-sourcing problems. 由于所有XML,您的性能会慢得多,但您也可以在中间获得行业标准协议,从而为单一来源问题提供双端保护。

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

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