java中如何存储rmi连接?

发布于 2024-08-12 10:52:02 字数 535 浏览 5 评论 0原文

我这里有问题。 我有一个通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追风人 2024-08-19 10:52:02

如果您无法修改 A,则 B 需要负责阻塞,直到 C 产生结果,并同步返回该结果RMI 方法的结果。

所以看来问题更多的是关于C如何回复B(或“Bs”,因为听起来你有一个这样的集群)而不是如何响应A

通常,这样的同步调用是通过 JMS 模拟的 创建临时队列,将其指定为消息的回复地址。因此,B 将创建一个临时队列,然后阻塞该队列,直到收到 C 返回的结果,然后将回复内容返回给 A< /代码>。

我可能不完全理解您的情况,但似乎任何其他方法都需要修改 AB 接口。

If you can't modify A, then B needs to be responsible for blocking until C 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 to B (or "Bs", since it sounds like you have a cluster of these) than how to respond to A.

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 from C, then return the content of the reply to A.

I might not understand your circumstances fully, but it seems like any other approach would require modifications to the AB interface.

惯饮孤独 2024-08-19 10:52:02

那么,既然 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?

悲凉≈ 2024-08-19 10:52:02

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文