Docker-Spring Cloud Config客户端,配置服务器发现问题

问题描述 投票:0回答:1

我正在尝试使用Spring Cloud Netflix Stack和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://[email protected]/prek/boot-netflix-problem.git

当spring cloud配置客户端“ constants-service”在bootstrap.properties中使用以下配置时

spring.application.name=constants-service
spring.cloud.config.uri=http://configserver:8888

然后一切似乎都可以正常工作,包括向“ Eureka”进行注册以及从configserver检索配置。

然后通过发现查找configserver,然后从恒定服务中检索配置,我按如下所示修改bootstrap.properties文件:

spring.application.name=constants-service
#Lookup through Eureka
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=CONFIGSERVER

上述更改通过使用Eureka主机名,localhost而不是发现来防止“ constants-service”连接到eureka,并且查找configserver服务和使用Eureka进行自注册均失败。

用于发现的application.properties是:

server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

configserver的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

对于常量服务是:

server.port=8080

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://discovery:8761/eureka

有人可以建议上述配置吗?

spring-cloud-netflix spring-cloud-config
1个回答
0
投票

您正在将应用程序切换为'Discovery First mode',因此您的constants-service应该了解Eureka,并从名称中获取configserver URL。

问题很简单:constants-service的bootstrap.properties不包含Eureka的URL,您应该将ureka客户端配置从git repo(application.properties)移至bootstrap.properties。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.