views:

430

answers:

3

When designing an distributed application in Java there seem to be a few technologies that address the same kind of problem. I have briefly read about Java Remote Method Invocation and Java Message Service, but it is hard to really see the difference. Java RMI seems to be more tightly coupled than JMS because JMS uses asynchronous communication, but otherwise I don't see any big differences.

  • What is the difference between them?
  • Is one of them newer than the other one?
  • Which one is more common/popular in enterprises?
  • What advantages do they have over each other?
  • When is one preferred over the other?
  • Do they differ much in how difficult they are to implement?

I also think that Web Services and CORBA address the same problem.

+6  A: 

You cannot really compare the two, its apples and oranges.

RMI is a form of Remote Procedure Call (RPC). It is a lightweight, Java specific API that expects the caller and receiver to be available at the time of communication.

JMS is a reliable messaging subsystem. Messages can be passed even if one of the parties is not available. It is an alternative to things like MQSeries.

RMI doesn't deal with guaranteed delivery or asynchronous responses, JMS does.

JMS allows loose coupling in the sense of availability. "Web Services" allows loose coupling in the sense of protocol and data but doesn't specify much in the way of reliable messaging, though some implementations do include this (Windows Communication Foundation) and some don't.

mrjoltcola
+6  A: 

You already know about method calls. What if the object that you want to invoke the method on is on a different computer? You use RMI to send the call from one computer (client) to the other (server). The client will wait (or "block") until the result comes back from the server. This is called synchronous operation.

JMS is different: it lets one computer send a message to another - like email. The first one doesn't have to wait for a response: it can keep doing whatever work it wants. There may not even be a response. The two computer systems don't necessarily work exactly in step, so this is called asynchronous.

Another way of thinking about the difference: RMI is like making a phone call, and JMS is like sending a text message.

RMI is a little older than JMS, but that's not really relevant. The two concepts are much much older than java.

There's not much difference in the complexity. I think that you should try doing a tutorial on each one. RMI and JMS

If you're starting a project from scratch, and you're not sure which one to use, then probably the synchronous/asynchronous issue is the best decision factor. If you're working on an existing system, it's probably best not to introduce too many new technologies. So if they're already using one, then I'd suggest it's probably best to stick with that one.

John
+4  A: 

Remote Method Invocation (RMI): 1.Java's native RPC interface 2.Remote objects can be run with similar semantics to local objects 3.The default implementation uses a proprietary binary communication protocol, but RMI can be implemented over SOAP

Java Messaging System (JMS) 1.Java's interface and specification to Message Oriented Middleware 2.Packets of data can be shipped to message queues and topics where they will be operated upon asynchronously. The queues or topics need not be remote 3.JMS server could be using RMI, SOAP, etc.

giri