Spring / Java,与另一台服务器上的命令行 Java 应用程序远程交互的好方法吗?

发布于 2024-10-23 12:55:29 字数 311 浏览 4 评论 0原文

我正在开发一个 Spring Web 应用程序,我需要与基于远程的命令行 java 应用程序进行交互,以便在此应用程序上运行简单的搜索查询并获取结果。我最初已将其集成到我的 Spring 应用程序中,但我的应用程序本身需要大量内存(它是一个涉及大量数据的应用程序),我认为它们不能再在一台服务器上共存。

我在 Amazon ec2 上运行所有内容,因此服务器之间的延迟应该非常低。我想我可以使用直接 SSH 连接,但不太确定这是否是最好的方法。我想让与之交互的命令行应用程序尽可能简单(如果不需要,我宁愿不将其变成网络服务)。我对 Java 还很陌生,如果这听起来像是一个基本问题,我很抱歉。

I am working on a Spring web application where I have a need to interact with a remotely based command-line java application to run a simple search query on this application and get back the results. I initially had integrated this into my Spring app but my app is, itself, needing a lot of memory (its an app that involves huge amounts of data) and I don't think they can coexist on one server anymore.

I am running everything on Amazon ec2 so the latency between the servers should be really low. I figure I could use a direct SSH connection but am not so sure if this is the best approach. I'd like to keep the command-line app I am interacting with as simple as possible (would rather not make it into a web-service if I don't have to). I'm still fairly new to Java so sorry if this sounds like a basic question.

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

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

发布评论

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

评论(2

安静 2024-10-30 12:55:29

除了 Web 服务之外,您还有多种选择。其中一些是:

  1. 协议缓冲区

  2. JMS

  3. 基于简单套接字的客户端/服务器 Java

  4. Thrift

You have several options other than a web service. Some of them are:

  1. Protocol Buffers

  2. JMS

  3. Simple socket based client/server Java

  4. Thrift

冰之心 2024-10-30 12:55:29

假设您在两端都有或可以有 spring -

使用 Spring 的远程处理支持。 (在这种情况下,RmiServiceExporter 的设置可能是最合适且最简单的)

它确实消除了所有样板代码,让您专注于业务/服务逻辑。

您可以编写一个 hello world 服务,并在不到 20 分钟的时间内从另一个 Java 程序中使用它。一旦你有了这个“基础设施”设置,你就可以自由地专注于你的实际业务逻辑。

(你绝对不必了解 rmi 才能使其正常工作,尽管如果你遇到问题,rmi 工作知识可能会有所帮助。但是,SO 社区是用来做什么的?;))

Assuming you have or can have spring on both ends -

Exposing service objects and consuming them from a different process becomes extremely trivial using Spring's remoting support. (RmiServiceExporter may be most appropriate and least trivial to setup in this case)

It really does away with all the boiler plate code and let's you focus on your business/service logic.

You can write a hello world service and consume it from another Java program in less than twenty minutes. Once you have this "infrastructure" setup, you are free to focus on your actual business logic.

(You absolutely don't have to know rmi to get this working though rmi working knowledge may help if you run into problems. But then, what is SO community for? ;))

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