spring - 使用 Spring Cloud 配置运行多实例微服务

标签 spring spring-boot microservices spring-cloud-config

我正在开发一个微服务,使用 Spring Boot ,公开 REST 端点。

为了满足可扩展性限制,将部署[同一]服务的多个实例(基本上是在需要时扩展,在不需要时缩小)。

我正在使用 Spring Cloud Config Server 向该服务提供配置(例如要绑定(bind)的端口和其他配置)。

由于服务公开了 REST api,如何配置配置服务器为微服务的每个实例提供唯一的端口?

一种可能的解决方案是在单独的计算机/VM 中运行服务或创建 Docker 容器并部署服务。如果无法从云配置服务器向服务提供随机端口,这可能是我的解决方案。

最佳答案

您可以使用不同的 Spring 配置文件来启动这三个实例。例如。第一个实例为 SPRING_PROFILES_ACTIVE=prod1,第二个实例为 SPRING_PROFILES_ACTIVE=prod2,依此类推。

然后您可以在 application-prod1.properties、application-prod2.properties 等(或在 yaml 文件中)设置端口。

您还可以在cloudfoundry中运行该应用程序。然后cloudfoundry将为您创建不同的容器。

关于spring - 使用 Spring Cloud 配置运行多实例微服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42002512/

相关文章:

java - Vert.X微服务: Multiple database access or using request-reply

需要 Spring 面试问题

java - 从 spring 检索代理实例

java - Camunda 在 Spring Boot 应用程序上禁用 DbHistoryEventHandler

java - 如何在 Spring HandlerInterceptorAdapter 中将 header 添加到 http 响应?

spring-boot - Istio 服务发现

spring - Hibernate 4.3 需要 Websphere RASWsLoggerFactory 吗?

java - Spring如何将同一个项目的bean拆分到多个Java进程中?

java - 如何让 Controller 使用特定的 @ControllerAdvice 而不是另一个?

jhipster - 将 "MicroService Gateway"连接到 "UAA Server"Jhipster 3.5.0