java中如何存储rmi连接?
我这里有问题。 我有一个通过 RMI 调用 B
的客户端 A
代码。之后,我通过 JMS 向实际实现 C
发送队列请求。但是,我不知道 A
的“地址”。有没有办法以某种方式存储连接数据,以便我稍后可以将数据返回到 A
?
基本上,B
可能有大量请求,并且需要将其同步到请求者。怎么做呢?
示例:
A:
...
rmiB.HelloWorld("Sys");
...
B:
String HelloWorld(String s) {
...
sendToJMS(s);
...
return????
}
C:
String HelloWorldOnJMS(String aff) {
return "aff+2"
}
I'm with a problem here.
I have a client A
code that calls a B
via RMI. After that I'm sending a queue request via JMS to the real implementation C
. However, I don't know the "address" of A
. Is there a way to store the connection data somehow so that I can return the data to A
later?
Basically the thing is that B
can have tons of requests and need to synchronize this to the requestor. How to do that?
Example:
A:
...
rmiB.HelloWorld("Sys");
...
B:
String HelloWorld(String s) {
...
sendToJMS(s);
...
return????
}
C:
String HelloWorldOnJMS(String aff) {
return "aff+2"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您无法修改
A
,则B
需要负责阻塞,直到C
产生结果,并同步返回该结果RMI 方法的结果。所以看来问题更多的是关于
C
如何回复B
(或“Bs”,因为听起来你有一个这样的集群)而不是如何响应A
。通常,这样的同步调用是通过 JMS 模拟的 创建临时队列, 和 将其指定为消息的回复地址。因此,
B
将创建一个临时队列,然后阻塞该队列,直到收到C
返回的结果,然后将回复内容返回给A< /代码>。
我可能不完全理解您的情况,但似乎任何其他方法都需要修改
A
–B
接口。If you can't modify
A
, thenB
needs to be responsible for blocking untilC
produces a result, and returning that result synchronous as the result of the RMI method.So it seems the problem is more about how
C
can reply toB
(or "Bs", since it sounds like you have a cluster of these) than how to respond toA
.Normally, synchronous calls like this are simulated via JMS by creating a temporary queue, and specifying that as the reply address on the message. So,
B
would create a temporary queue, then block on that queue until it received the result back fromC
, then return the content of the reply toA
.I might not understand your circumstances fully, but it seems like any other approach would require modifications to the
A
–B
interface.那么,既然 A 和 B 已经通过 RMI 定位器连接,为什么不让 A 也注册一个服务,然后让 B 调用该服务呢?
Well, since A and B are already connected via a RMI locator, why not just have A register a service as well, and then let B call that service?
RMI 呼叫转发到 JMSService?听起来 Apache Camel 正是您所需要的;它是一个用于进行此类企业集成的框架。
组件页面提供了如何设置 RMI 和 JMS(以及无数其他)端点的示例。然后,您将使用其强大的 DSL 编写一条路由,将消息从一个端点转发到另一个端点。
An RMI call forwarding to a JMSService? Sounds like Apache Camel is exactly what you need; its a framework for doing just this sort of Enterprise integration.
The components page has examples of how to set up RMI and JMS (and myriad other) endpoints. You'll then write a route using its powerful DSL to forward messages from one endpoint to the other.