首页 文章

使用spring cloud config运行多个实例微服务

提问于
浏览
1

我正在开发一个 microservice, using Spring Boot ,它暴露了REST endpoints .

为了满足可扩展性约束,将部署 multiple instance of the [same] service (基本上在需要时向上扩展,在不需要时向下扩展) .

我正在使用 Spring Cloud Config Server 为此服务提供配置(例如端口绑定和其他配置) .

Since the service exposing REST api, How can configure the config server to supply a unique port to each instance of the microservice?

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

2 回答

  • 2

    您可以使用不同的Spring配置文件启动三个实例中的每一个 . 例如 . SPRING_PROFILES_ACTIVE = prod1为第一个实例,SPRING_PROFILES_ACTIVE = prod2为第二个,等等 .

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

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

  • 0

    您是否尝试过使用带有Rabbit MQ的spring-cloud-bus,它基本上是通过POST总线/刷新将您的配置更改广播到应用程序的所有实例 .

相关问题