Docker - Spring 云配置客户端,配置服务器发现问题
Docker - Spring Cloud Config Client, Issue with Config Server Discovery
我正在试验 Spring Cloud Netflix 堆栈和 Spring Cloud Config Server 和客户端。
为此,我设置了一个最小示例,如下面的 docker-compose 文件所示。
version: '3'
services:
#Eureka Service
discovery:
container_name: discovery
image: jbprek/discovery:latest
ports:
- "8761:8761"
#Spring cloud config server
configservice:
container_name: configserver
image: jbprek/configserver:latest
ports:
- "8888:8888"
depends_on:
- discovery
#Example microservice using discovery and spring cloud config
constants-service:
container_name: constants-service
ports:
- "8080:8080"
image: jbprek/constants-service:latest
depends_on:
- discovery
- configservice
根据各种示例,发现和配置服务器的实现最少,完整代码可以通过以下方式克隆:
git clone https://prek@bitbucket.org/prek/boot-netflix-problem.git
当spring云配置客户端"constants-service"在bootstrap.properties
中使用如下配置
spring.application.name=constants-service
spring.cloud.config.uri=http://configserver:8888
然后一切似乎都正常工作,包括使用 "Eureka" 注册和从配置服务器检索配置。
然后通过发现查找配置服务器,然后从常量服务中检索配置,我修改bootstrap.properties文件如下:
spring.application.name=constants-service
#Lookup through Eureka
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=CONFIGSERVER
以上更改具有阻止 "constants-service" 连接到 eureka 的效果,通过使用 localhost 作为 Eureka 主机名而不是发现,并且配置服务器服务的查找和 Eureka 的自注册都失败。
发现的application.properties是:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
配置服务器的 application.properties 是:
server.port=8888
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
spring.cloud.config.server.git.uri=https://bitbucket.org/prek/boot-netflix-problem-config-data.git
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.discovery.enabled=false
常量服务是:
spring.application.name=constants-service
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
有人可以建议以上配置吗?
更新
根据@nmyk 为常量服务提供的以下答案,它是 Eureka(发现)客户端和 Spring Cloud Config 客户端,发现和配置的配置应包含在 bootstrap.properties 文件所以给定上面提到的例子,常量服务的 boostrap.properties 文件可以是:
spring.application.name=constants-service
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=CONFIGSERVER
您正在将您的应用程序切换到“Discovery First mode”,因此您的 constants-service 应该了解 Eureka 并获取 configserver URL 从它的名字。
问题很简单:你的 constants-service 的 bootstrap.properties 不包含 URL 到 Eureka,你应该将 eureka 客户端配置从 git 回购 (application.properties) 到 bootstrap.properties.
我正在试验 Spring Cloud Netflix 堆栈和 Spring Cloud Config Server 和客户端。
为此,我设置了一个最小示例,如下面的 docker-compose 文件所示。
version: '3'
services:
#Eureka Service
discovery:
container_name: discovery
image: jbprek/discovery:latest
ports:
- "8761:8761"
#Spring cloud config server
configservice:
container_name: configserver
image: jbprek/configserver:latest
ports:
- "8888:8888"
depends_on:
- discovery
#Example microservice using discovery and spring cloud config
constants-service:
container_name: constants-service
ports:
- "8080:8080"
image: jbprek/constants-service:latest
depends_on:
- discovery
- configservice
根据各种示例,发现和配置服务器的实现最少,完整代码可以通过以下方式克隆:
git clone https://prek@bitbucket.org/prek/boot-netflix-problem.git
当spring云配置客户端"constants-service"在bootstrap.properties
中使用如下配置spring.application.name=constants-service
spring.cloud.config.uri=http://configserver:8888
然后一切似乎都正常工作,包括使用 "Eureka" 注册和从配置服务器检索配置。
然后通过发现查找配置服务器,然后从常量服务中检索配置,我修改bootstrap.properties文件如下:
spring.application.name=constants-service
#Lookup through Eureka
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=CONFIGSERVER
以上更改具有阻止 "constants-service" 连接到 eureka 的效果,通过使用 localhost 作为 Eureka 主机名而不是发现,并且配置服务器服务的查找和 Eureka 的自注册都失败。
发现的application.properties是:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
配置服务器的 application.properties 是:
server.port=8888
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
spring.cloud.config.server.git.uri=https://bitbucket.org/prek/boot-netflix-problem-config-data.git
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.discovery.enabled=false
常量服务是:
spring.application.name=constants-service
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
有人可以建议以上配置吗?
更新
根据@nmyk 为常量服务提供的以下答案,它是 Eureka(发现)客户端和 Spring Cloud Config 客户端,发现和配置的配置应包含在 bootstrap.properties 文件所以给定上面提到的例子,常量服务的 boostrap.properties 文件可以是:
spring.application.name=constants-service
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=CONFIGSERVER
您正在将您的应用程序切换到“Discovery First mode”,因此您的 constants-service 应该了解 Eureka 并获取 configserver URL 从它的名字。
问题很简单:你的 constants-service 的 bootstrap.properties 不包含 URL 到 Eureka,你应该将 eureka 客户端配置从 git 回购 (application.properties) 到 bootstrap.properties.