English 中文(简体)
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.

最佳回答

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.

问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签