简体   繁体   English

Java-消耗运行在同一计算机不同端口上的Rest服务的最佳方法是什么?

[英]Java - What is the best way to consume Rest service running at different port of the same machine?

I am creating an application where I have to consume a RestFul service that is running at a different port of the same machine. 我正在创建一个应用程序,在其中我必须使用在同一台计算机的不同端口上运行的RestFul服务。 I can definitely hard code url as "localhost:/url" in the client code but I dont think that is the best way to do it. 我绝对可以在客户端代码中将URL硬编码为“ localhost:/ url”,但我认为这不是最好的方法。

Is the decision accidental or inherent? 决策是偶然的还是固有的?

The proper action depends on the reason why the other service is running at a different port on the same machine. 正确的操作取决于为什么其他服务在同一台机器上的不同端口上运行的原因。 If the reason is accidental - ie at this moment, the service happens to reside on the same host, then you'd want the URL root be configurable. 如果原因是偶然的-即此刻,该服务恰好位于同一主机上,则您希望URL根是可配置的。 If the reason is inherent - ie there are two separate executables interacting through a REST interface but built, packaged, distributed and deployed as a single project, then you might want to ensure that they're on the same (virtual) machine by eg packaging them both in a single Docker container or something like that. 如果原因是内在的-即,有两个单独的可执行文件通过REST接口进行交互,但是作为单个项目进行构建,打包,分发和部署,那么您可能想要通过打包等方式确保它们位于同一台(虚拟)计算机上它们都在单个Docker容器中或类似的容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Java 6 使用 REST 服务 - Consume REST service with Java 6 使 .net 客户端从 Java 服务器消费服务的最佳方法是什么? - What is the best way to make a .net client consume service from a Java server? 在Lagom中使用外部REST服务的最简单方法是什么? - What is the simplest way to consume an external REST service in Lagom? 在java中测试REST服务的最佳方法 - Best way to test a REST service in java 在jboss 7.0.2中的同一端口和机器上运行不同的应用程序 - running different application on same port and machine in jboss 7.0.2 在同一台机器上运行的Java和C ++应用程序之间IPC的最佳方法是什么? - What is the best approach for IPC between Java and C++ apps running on the same machine? 构建和公开机器学习模型 REST api 的最佳方法是什么? - What is the best way to build and expose a Machine Learning model REST api? 如何使Android应用程序消耗运行在同一台机器上的Tomcat上的JAX Jersey Web Service - How to make android application consume JAX Jersey Web Service running on tomcat on same machine 绑定到Netty中同一处理程序上不同端口的最佳方法是什么? - What is the best approach to bind to different port on same handler in Netty? 如何使用java使用Web服务休息? - How to consume web service rest with java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM