Java 可以与 System V Linux 消息队列交互吗?

发布于 2024-11-16 02:52:40 字数 420 浏览 0 评论 0原文

我需要将信息从 shell 脚本(从基于 Linux 的应用程序调用)传递到 java 应用程序。

命名管道很痛苦,因为如果不考虑对管道读/写端的复杂影响,我就无法启动/停止任一服务。

套接字很难,因为如果重新启动监听进程,就没有排队机制,并且简单的实现需要不断创建新的套接字(否则 shell 脚本会因 check-and-restart-socket 而变得非常复杂,并且排队代码)。

我最近阅读了有关这些System V/POSIX linux 消息队列的内容。我正在运行 Fedora 12,想知道是否有一种好方法来配置这些消息队列并通过 Java 与它们交互

I need to pass information from a shell script (called from a linux based app) to a java application.

Named pipes are a pain because I can't start/stop either service without considering complex repercussions to the read/write ends of the pipes.

Sockets are tough because if the listening process is restarted there's no queuing mechanism, and simple implementations require new sockets be constantly created (else the shell script will get very complex with check-and-restart-socket, and queuing code).

I was recently reading about these System V/POSIX linux message queues. I'm running Fedora 12, and wonder if there's a good way to configure these message queues and interact with them from Java.

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

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

发布评论

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

评论(1

拥抱没勇气 2024-11-23 02:52:40

您不能直接使用它们,您必须执行一些 JNI 魔法才能将它们连接在一起。

您在使用管道时遇到什么问题? Java 将它们视为普通文件。我没有广泛使用它们,但我对 Pipes 没有任何真正的问题。唯一的细节是,如果生产者跟不上,管道读取器需要不断地重新打开管道。

但如果任何一方失败,另一方就会阻塞等待另一方恢复。

您只需要小心从管道读取缓冲区即可。如果您从管道读入缓冲区,然后失败,则该数据将丢失。

You can't use them directly, you'd have to do some JNI wizardry to interface them together.

What problems are you having with Pipes? Java sees those as just generic files. I haven't used them extensively, but I didn't have any real problems with Pipes. The only detail there was the pipe reader needs to continually reopen the pipe if the producers can't keep up.

But if either side fails, the other side just blocks waiting for the other to recover.

You just have to be careful with buffer reads from the pipe. If you read from the pipe in to a buffer, and then fail, that data is lost.

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