RMI vs. Web Services. What's best for Java2Jav

2019-01-30 02:18发布

I'm new to both Web Services and RMI and I wonder which is the better way to do remoting between different web applications, when these applications are all written in Java, that is when different programming languages don't matter (which would be the advantage of WS).

While on the one hand I would guess that there's a performance overhead when using web services (does anyone have some numbers to prove that?), on the other hand it seems to me that web services are much more loosely coupled and can be used to implement a more service-oriented architecture (SOA) (which isn't possible with RMI, right?).

Although this is quite a general question, what's your opinion?

Thanks

9条回答
贪生不怕死
2楼-- · 2019-01-30 02:59

As a Spring bigot and an exponent of SOA for many years I'd advise Spring remoting. This flavour of service exporter will do the trick for RMI.

org.springframework.remoting.rmi.RmiServiceExporter

Other transports are of course available. The serialisation thing is quite managable if you version your interfaces (end-points) and DTOs sensibly & manage serialisation UUIDs properly. We postfix 'Alpha', 'Bravo' to our interfaces and objects and increment, decrement & reinvent where and when necessary. We also fix our serialisation UUIDs to 1 and ensure changes are only addative, otherwise we move from say, 'Bravo' to 'Charlie'. All managable in an Enterprise setup.

查看更多
叼着烟拽天下
3楼-- · 2019-01-30 03:02

The web services do allow a loosely coupled architecture. With RMI, you have to make sure that the class definitions stay in sync in all application instances, which means that you always have to deploy all of them at the same time even if only one of them is changed (not necessarily, but it is required quite often because of serial UUIDs and whatnot)

Also it is not very scalable, which might be an issue if you want to have load balancers.

In my mind RMI works best for smaller, local applications, that are not internet-related but still need to be decoupled. I've used it to have a java application that handles electronic communications and I was quite satisfied with the results. For other applications that require more complex deployment and work across the internet, I rather use web services.

查看更多
来,给爷笑一个
4楼-- · 2019-01-30 03:03

One thing that favors WS over RMI is that WS works over HTTP port 80/443 which are normally not blocked at firewalls , can work behind NAT etc. RMI has a much complex underlying network protocol which requires you to open up RMI ports, and also might not work if the client is NATTED. Secondly with RMI you are limiting your slef to JAVA-JAVA communication, while with Webservies there is no such limitation. It is much easier to debug Webservices over the wire as the data is SOAP/HTTP , which can be easily captured via sniffing tools for debugging. I don't know of an easy way to do this over RMI. Besides RMI is really very old and hasn't received much attention for last few years. It was big back in the days when CORBA was big , and both RMI CORBA are really antiquated technologies. The best option is REST style Webservices.

查看更多
登录 后发表回答