Java RMI 和 JMS 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2576446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between Java RMI and JMS?
提问by Jonas
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 Invocationand 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.
在用 Java 设计分布式应用程序时,似乎有一些技术可以解决同样的问题。我已经简要地阅读了Java Remote Method Invocation和Java Message Service,但很难真正看出它们之间的区别。Java RMI 似乎比 JMS 耦合更紧密,因为 JMS 使用异步通信,但除此之外我没有看到任何大的差异。
- 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 Servicesand CORBAaddress the same problem.
我还认为Web 服务和CORBA解决了同样的问题。
采纳答案by codenheim
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.
RMI 是远程过程调用 (RPC) 的一种形式。它是一个轻量级的、Java 特定的 API,期望调用方和接收方在通信时可用。
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.
JMS 是一个可靠的消息传递 API。JMS 提供程序适用于各种消息传递系统。如果提供者实现了这一点,即使其中一方不可用,也可以传递消息。我熟悉的两个是 TIBCO 和 IBM MQ。
RMI doesn't deal with guaranteed delivery or asynchronous responses, JMS may, depending on the provider.
RMI 不处理保证交付或异步响应,JMS 可能会处理,这取决于提供者。
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.
JMS 允许在可用性意义上的松散耦合。“Web 服务”允许在协议和数据意义上的松散耦合,但在可靠消息传递方面没有指定太多,尽管有些实现确实包括这个(Windows 通信基础),有些则没有。
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.
编辑:根据评论修改。当我在 2010 年写这个答案时,我的经验实际上只有一个 JMS 提供者,我实际上并不知道没有默认的 JMS 提供者。
回答by John
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 synchronousoperation.
您已经了解方法调用。如果您要对其调用方法的对象在另一台计算机上怎么办?您使用 RMI 将调用从一台计算机(客户端)发送到另一台(服务器)。客户端将等待(或“阻塞”)直到结果从服务器返回。这称为同步操作。
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.
JMS 不同:它允许一台计算机向另一台计算机发送消息——比如电子邮件。第一个不必等待响应:它可以继续做它想做的任何工作。甚至可能没有回应。两个计算机系统不一定完全同步工作,因此称为异步。
Another way of thinking about the difference: RMI is like making a phone call, and JMS is like sending a text message.
另一种思考差异的方式:RMI就像打电话,而JMS就像发短信。
RMI is a little older than JMS, but that's not really relevant. The two concepts are much much older than java.
RMI 比 JMS 老一点,但这并不重要。这两个概念比java要古老得多。
There's not much difference in the complexity. I think that you should try doing a tutorial on each one. RMIand JMS
复杂度没有太大区别。我认为你应该尝试对每一个都做一个教程。RMI和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.
如果您从头开始一个项目,并且不确定使用哪一个,那么同步/异步问题可能是最佳决策因素。如果您在现有系统上工作,最好不要引入太多新技术。所以如果他们已经在使用一个,那么我建议最好坚持使用那个。

