寻找一些有关分布式应用程序和消息传递的 Java 良好实践建议

发布于 2024-10-08 09:30:44 字数 246 浏览 0 评论 0原文

一些背景信息。这是一个具有多个节点的分布式应用程序。 “通信”线程发送和接收这些节点之间发送的所有消息。这是无法改变的。

“doStuff”线程要求“通信”线程向节点发送消息。然后它需要等待其他节点的响应。 “通信”线程将收到此响应消息。然后它需要将此消息传递到正确的“doStuff”线程。

我不确定需要在节点或消息中存储什么类型的信息,以确保正确的线程始终收到响应消息。

寻找有关如何实现这一目标的一些建议。感谢您的阅读:)

Some background information. This is a distributed application with multiples nodes. A 'communication' thread sends and receives all messages sent between these nodes. This cannot be changed.

A 'doStuff' thread asks the 'communication' thread to send a message to a node. It then needs to wait for a response from the other node. The 'communication' thread will receive this response message. It then needs to deliver this message to the correct 'doStuff' thread.

I am unsure what sort of information needs to be stored at the node or within the message to ensure that the correct thread always receives the response message.

Looking for some advice upon how to achieve this. Thanks for reading :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

无言温柔 2024-10-15 09:30:44

您可能希望将某种消息 ID 附加到要包含在响应中的传出消息中。序列号或 UUID 可能可以完成这项工作。然后,您的通信器线程可以跟踪(映射?)哪个“doStuff”线程正在等待给定的响应并将其传回。

您还可以跟踪请求的发送时间,以便如果未收到响应,通信器线程可以通知 doStuff 线程未收到响应。

You probably want to attach some sort of message id to the outgoing message to be included in the response. A sequential number or a UUID would probably do the job. Your communicator thread can then keep track (a map?) of what "doStuff" thread was waiting for a given response and pass it back.

You could also keep track of when the request was sent so that if a response isn't received the communicator thread can notify the doStuff thread that the response wasn't received.

中性美 2024-10-15 09:30:44

看起来不是很困难

使用线程 id 或 doStuff 线程发明的其他不透明令牌,该令牌由通信线程存储(映射到调用线程 id)并随响应一起返回 通信线程在映射来识别相应的线程。

或者我错过了什么?

It doesn't seem very difficult

Use either a thread id, or other opaque token invented by the doStuff thread which is stored by the Communication thread (mapped to the calling thread id) and returned with the response The communication thread looks it up in the Map to identify the corresponding thread.

Or am I missing something?

不弃不离 2024-10-15 09:30:44

使用 JMS 是一种选择吗?如果是这样,您可能会发现这比“自己动手”更实用。一般来说,异步消息传递是一个已解决的问题。如果可以选择 JMS,请查看 TopicRequestor 和/或特别是 QueueRequestor

Is using JMS an option at all? If so, you might find that more practical than doing "roll your own." Asynchronous message passing, in general, is a solved problem. If JMS is an option, look at TopicRequestor and/or QueueRequestor in particular.

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