Sha*_*baz 8 spring-boot spring-cloud docker-compose spring-cloud-netflix spring-cloud-config
我有一个spring cloud配置服务器并将其打包为docker镜像,然后我也有spring cloud eureka服务器也打包为docker镜像。
当我使用docker compose运行两者时,出现以下错误。
discovery-service_1 | 2017-06-24 15:36:12.059 INFO 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://config-service:9001
discovery-service_1 | 2017-06-24 15:36:12.997 WARN 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://config-service:9001/cls-discovery-service/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
尽管配置服务已启动并成功运行,但是由于某种原因,发现服务仍然找不到它。
这里使用的Docker撰写文件是这个
version: '2'
services:
config-service:
image: cloudsea/cls-config-service
ports:
- 9001:9001
expose:
- "9001"
discovery-service:
image: cloudsea/cls-discovery-service
depends_on:
- config-service
environment:
CLOUD_SEA_CONFIG_SERVER_URI: http://config-service:9001
EUREKA_DEFAULT_ZONE_URL: http://discovery-service:8761/eureka/
ports:
- 8761:8761
links:
- config-service:config-service
以下是DISCOVERY SERVICE 的bootstrap.properties
spring.cloud.config.uri = ${CLOUD_SEA_CONFIG_SERVER_URI:http://localhost:9001}
spring.application.name = ${SPRING_APPLICATION_NAME:cls-discovery-service}
以下是位于github中的DISCOVERY SERVICE 的cls-discovery-service.properties。
server.port=${SERVER_PORT:8761}
eureka.client.registerWithEureka: false
eureka.client.fetchRegistry: false
eureka.client.serviceUrl.defaultZone: ${EUREKA_DEFAULT_ZONE_URL:http://localhost:8761/eureka/}
eureka.server.eviction-interval-timer-in-ms: 1000
我假设我的docker-compose.yml出了点问题,但我不确定。
任何帮助我都会坚持几个小时...接近几天:(
我通过将此配置添加到发现服务的bootstrap.yml中来解决了该问题。
spring:
cloud:
config:
failFast: true
retry:
initialInterval: 3000
multiplier: 1.3
maxInterval: 5000
maxAttempts: 20
Run Code Online (Sandbox Code Playgroud)
然后将spring-boot-starter-aop和spring-retry添加到发现服务的maven依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot-starter-aop.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring-retry.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题在于它们都是同时启动的。但是发现服务取决于配置服务。
当您启动发现服务时,它将一遍又一遍地说“ 从服务器获取配置 ”,直到配置服务启动为止。
config服务启动后,发现服务将成功获取其配置,然后将自行启动。
| 归档时间: |
|
| 查看次数: |
3261 次 |
| 最近记录: |