RMI vs. Web Services. What's best for Java2Java remoting? [closed]
Asked Answered
A

9

48

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

Alvaroalveolar answered 19/9, 2008 at 10:32 Comment(0)
C
35

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.

Chenee answered 19/9, 2008 at 10:56 Comment(3)
"Also it is not very scalable" why do you think it wont scale ?Barque
Upvoted the comment above. One should be really specific when one calls something "not scalable" or "not production ready" or "not suitable for large apps"Healy
I mentioned above that the reason why I consider it problematic is that object class definitions have to remain in sync across all deployments, which either means that you have to be very careful of what you deploy or very careful how you extend your classes. Both things, although doable, often lead to mistakes. Can it be done? sure! will it work? sure it will! will the users make mistakes? most assuredly!Follicle
B
13

Whether you use Web Services or a more "native" approach depends on the environment as well. If you have to pass through a proxy or some corporate firewall(s), Web Services are more likely to work since they are relying on HTTP only. RMI requires you to open another port for your application which may be difficult (not technically, though) in some environments...

If you know that this issue is not a problem, you should consider using RMI. SOA does not depend on technology so much as on good service design. If you have an EJB container, you can call session beans via RMI and additionally expose them as web services, if you really need to, by the way.

The performance depends on the data that you are planning to exchange. If you want to send complex object nets from one application to another, it's probably faster with RMI, since it's transfered in a binary format (usually). If you have some kind of textual/XML content anyway, web services may be equivalent or even faster, since then you would not need to convert anything at all (for communication).

HTH,
Martin

Benedick answered 19/9, 2008 at 10:48 Comment(2)
I have a problem, the web services(textual) may be even faster than rmi. So, what will happen if we use serializer/deserializer(s) ex:-jacson for both ends. The serialization and deserialization have costs. What would be the overall transmission cost?? Will overall process be faster than rmi. This is a poblem I have in appliation development. Thank you!Rapallo
Nicely explained, yes RMI is used when there's a need to share complex objects. For textual information, use HTTP protocol, use REST or SOAP for easy to read data.Thermotaxis
P
11

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.

Parcel answered 14/11, 2010 at 17:25 Comment(1)
As you said using Sniffing tools can also be used by others to find the sensitive data transfer :)Comitative
S
6

My experience with RMI and Web Services mirrors your guesses above. In general, RMI's performance exceeds web services, if the communication requirement is for complex objects. The JEE interface specification needs to be explicitly specified for Web Services.

Note that Web Services are interoperable whereas RMI is not (in terms of the technologies of Client and Server). I tend to use Web Services when I had one or more external partners who were implementing the interface, but RMI if I was in control of both ends of the connection.

Septuplet answered 19/9, 2008 at 10:43 Comment(0)
P
2

RMI may be the better direction if you need to maintain complex state.

Police answered 8/10, 2008 at 14:8 Comment(0)
M
2

@Martin Klinke

"The performance depends on the data that you are planning to exchange. If you want to send complex object nets from one application to another, it's probably faster with RMI, since it's transfered in a binary format (usually). If you have some kind of textual/XML content anyway, web services may be equivalent or even faster, since then you would not need to convert anything at all (for communication)."

As far as I know the performance issue makes difference during serialization-deserialization in other words marshalling-demarshalling process.I am not sure both these terms are same btw In distributed programming,I am not talking about the process which happens in the same JVM,it's about how you copy data.It is either pass by value or pass by reference.Binary format corresponds to pass by value which means copying an object to remote server in binaries.If you have any doubt until now I d like to hear

what's the difference between sending in binary format and textual/xml content in terms of marshalling-demarshalling or serialization-deserialization?

I am just guessin.It does not depend on what kind of data you send.Whatever data type you send it'll be part of marshalling-demarshalling process and at the end will be sent in binaries right?

cheers Hakki

Macaroni answered 23/4, 2013 at 10:11 Comment(0)
C
1

What about Spring Remoting. It combines REST-like HTTP protocol with binary format of RMI. Works perfectly for me.

Charlie answered 5/12, 2008 at 10:19 Comment(0)
E
1

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.

Eviscerate answered 12/4, 2016 at 12:58 Comment(0)
M
-1

For Spring Remoting (I guessed you mean HTTP Invoker), both side should use Spring, if it is the case it can be discussed.

For a Java to Java application RMI is a good solutionö, JAX-RPC or JAX-WS for Java-to-Java communication should be avoided if the clients are not under your control or might move to another platform.

Mcphail answered 20/4, 2009 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.