简体   繁体   English

在仅Java环境中Web服务和RMI的优缺点是什么?

[英]What are the pros and cons of Web Services and RMI in a Java-only environment?

When developing distributed applications, all written in Java by the same company, would you choose Web Services or RMI? 在开发同一家公司用Java编写的分布式应用程序时,您会选择Web服务还是RMI? What are the pros and cons in terms of performance, loose coupling, ease of use, ...? 在性能,松散耦合,易用性方面,有哪些优点和缺点? Would anyone choose WS? 有人会选择WS吗? Can you build a service-oriented architecture with RMI? 你能用RMI构建面向服务的架构吗?

I'd try to think about it this way: 我试着这样思考:

Are you going for independent services running beneath each other, and those services may be accessed by non-java applications some time in the future? 您是否打算在彼此之下运行独立服务,这些服务可能会在未来的某个时间被非Java应用程序访问? Then go for web services. 然后去寻找网络服务。

Do you just want to spread parts of an application (mind the singular) over several servers? 您是否只想在多个服务器上传播应用程序的一部分(请注意单数)? Then go for RMI and you won't have to leave the Java universe to get everything working together tightly coupled. 然后转到RMI,您将不必离开Java Universe以使所有内容紧密耦合在一起。

I would choose WS. 我会选择WS。

  • It is unlikely that WS/RMI will be your bottleneck. WS / RMI不太可能成为您的瓶颈。
  • Why to close the door for other possible technologies in the future? 为什么将来关闭其他可能技术的大门?
  • RMI might have problem if version of classes on client/server get out of sync. 如果客户端/服务器上的类版本不同步,则RMI可能有问题。

And... I would most likely choose REST services. 而且......我很可能会选择REST服务。

If You Aren't Gonna Need It (interop with non-Java), and you probably aren't, RMI is going to be better; 如果你不需要它(与非Java互操作),你可能不是,RMI会更好; less code, less configuration, less bandwidth overhead. 代码更少,配置更少,带宽开销更少。

An option if you are scared that you Are Gonna Need It is to use EJB3; 如果你害怕你将需要它是一个选项它是使用EJB3; it uses RMI, is very easy to setup and deploy, but also allows you to turn your calls into Web Services easily if you need them. 它使用RMI,非常易于设置和部署,但如果您需要,还可以让您轻松将呼叫转换为Web服务。

Whatever you do, do not create your own thing; 无论你做什么,都不要创造自己的东西; stick to a standard. 坚持标准。

my choices are: 我的选择是:

standard java serialization - pros : imho offers the most performance, simple to implement (I'm using Spring to expose local interface as remote one); 标准的java序列化 - 专业:imho提供最高性能,易于实现(我使用Spring将本地接口公开为远程接口); cons : serialization doesn't work between different jvm versions 缺点:序列化在不同的jvm版本之间不起作用

binary serialization (for example hessian from jetty) - pros : same performance as with java serialization and works between different jvm versions 二进制序列化(例如来自jetty的hessian) - 优点:与java序列化相同的性能,可在不同的jvm版本之间工作

WS: only if there is a need in interoperability between different platforms java + .net , otherwise it is just too haveweight. WS:只有在不同平台java + .net之间需要互操作性时才需要,否则它只是太重了。

RMI is a great rapid-development transport, but I would advise against using it in a production environment. RMI是一种快速发展的快速交通工具,但我建议不要在生产环境中使用它。 The serialization compatibility problem can make things awkward, you have to coordinate your deployments very carefully. 序列化兼容性问题可能会使事情变得尴尬,您必须非常小心地协调部署。

WebServices are inefficient, yes, but just through hardware at it. Web服务是低效的,是的,但只是通过它的硬件。 Alternatively, use plain, lightweight XML-over-HTTP, rather than full-fat SOAP/WSDL. 或者,使用简单,轻量级的XML-over-HTTP,而不是全脂SOAP / WSDL。

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

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