[英]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”,但我认为这不是最好的方法。
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.