Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Java RMI and JMS?

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.

like image 249
Jonas Avatar asked Apr 05 '10 00:04

Jonas


People also ask

What is Java RMI used for?

RMI treats a remote object differently from a non-remote object when the object is passed from one Java virtual machine to another Java virtual machine. Rather than making a copy of the implementation object in the receiving Java virtual machine, RMI passes a remote stub for a remote object.

What protocol does Java RMI use?

On top of the TCP/IP layer, RMI uses a wire-level protocol called Java Remote Method Protocol (JRMP), which works like this: Objects that require remote behavior should extend the RemoteObject class, typically through the UnicastRemoteObject subclass.

What is one important difference between the use of Java RMI and Corba?

Java RMI is a server-centric model. CORBA is a peer-to-peer system. RMI uses the Java Remote Method Protocol as its underlying remoting protocol. CORBA use Internet Inter- ORB Protocol as its underlying remoting protocol.

What is Java RMI in distributed system?

Remote Method Invocation (RMI) is Java's implementation of object-to-object communication among Java objects to realize a distributed computing model. RMI allows us to distribute our objects on various machines, and invoke methods on the objects located on remote sites.


2 Answers

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.

like image 107
John Avatar answered Oct 06 '22 00:10

John


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 API. JMS providers exist for various messaging systems. Messages can be passed even if one of the parties is not available if the provider implements that. The two I am familiar with are TIBCO and IBM MQ.

RMI doesn't deal with guaranteed delivery or asynchronous responses, JMS may, depending on the provider.

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.

EDITED: Revised per comments. When I wrote this answer in 2010 my experience was actually with only one JMS provider and I didn't actually know there was no default JMS provider.

like image 40
codenheim Avatar answered Oct 06 '22 00:10

codenheim