基于Eureka的配置服务器断开执行器端点

时间:2015-06-24 22:10:38

标签: spring-cloud

我设置我的服务以使用基于Spring cloud eureka的配置服务器。

版本信息:spring cloud 1.0.1.RELEASE

当我将其设置为固定端点时,我可以看到它获得正确的配置文件,并且我可以访问执行器端点,如健康,信息等,因此... / manage / info返回正确的信息。

然而,当我将其设置为使用发现时,尝试访问它们时,相同的执行器端点超时。

在每种情况下都会检索并下载配置文件(包含日志文件)。

我是如何设置配置服务器和书签服务(使用配置服务器的服务)的?

我的配置服务器设置如下:

server:
  port: 8888
  contextPath: /configurationservice

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    statusPageUrlPath: /configurationservice/info
    homePageUrlPath: /configurationservice/
    healthCheckUrlPath: /configurationservice/health
    preferIpAddress: true

spring:
  cloud:
    config:
      server:
        native:
          searchLocations: file:/Users/larrymitchell/libertas/configserver/configfiles

服务bootstrap.yml设置为:

spring:
  profiles:
    default: development
    active: development
  application:
    name: bookmarkservice
  cloud:
    config:
      enabled: true # note this needs to be turned on if you wnat the config server to work
#      uri: http://localhost:8888/configurationservice
      label: 1.0.0
      discovery:
        enabled: true
        serviceId: configurationservice

application.yml设置为:

# general spring settings
spring:
  application:
    name: bookmarkservice
  profiles:
    default: development
    active: development    
# name of the service
service:
  name: bookmarkservice

# embedded web server settings
# some of these are specific to tomcat
server:
  port: 9001
  # the context path is the part after http:/localhost:8080
  contextPath: /bookmarkservice
  tomcat:
    basedir: target/tomcat
    uri-encoding: UTF-8

management:
  context-path: /manage
  security:
    enabled: false

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    statusPageUrlPath: /bookmarkservice/manage/info
    homePageUrlPath: /bookmarkservice/manage
    healthCheckUrlPath: /bookmarkservice/manage/health
    preferIpAddress: true

书签服务的启动日志如下:

2015-06-24 17:52:49.806 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Created GET request for "http://10.132.1.56:8888/configurationservice/bookmarkservice/development/1.0.0"
2015-06-24 17:52:49.890 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Setting request Accept header to [application/json, application/*+json]
2015-06-24 17:52:50.439 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : GET request for "http://10.132.1.56:8888/configurationservice/bookmarkservice/development/1.0.0" resulted in 200 (OK)
2015-06-24 17:52:50.441 DEBUG 11234 --- [           main] o.s.web.client.RestTemplate              : Reading [class org.springframework.cloud.config.environment.Environment] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2b07e607]
2015-06-24 17:52:50.466  INFO 11234 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='file:/Users/larrymitchell/libertas/configserver/configfiles/1.0.0/bookmarkservice-development.yml']]]
2015-06-24 17:52:50.503  INFO 11234 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5fa23965: startup date [Wed Jun 24 17:52:50 EDT 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@5cced717
2015-06-24 17:52:51.723  WARN 11234 --- [           main] .i.s.PathMatchingResourcePatternResolver : Skipping [/var/folders/kq/ykvl3t4n3l71p7s9ymywb4ym0000gn/T/spring-boot-libs/06f98804e83cf4a94380b46591b976b1d17c36b8-eureka-client-1.1.147.jar] because it does not denote a directory
2015-06-24 17:52:53.662  INFO 11234 --- [           main] o.s.b.f.config.PropertiesFactoryBean     : Loading properties file from URL [jar:file:/Users/larrymitchell/libertas/vipaas/applicationservices/bookmarkservice/target/bookmarkservice.jar!/lib/spring-integration-core-4.1.2.RELEASE.jar!/META-INF/spring.integration.default.properties]

1 个答案:

答案 0 :(得分:1)

好的,在与另一位同事讨论之后,我发现了实际问题是什么。 令人困惑的部分原因是我正在使用弹簧云(https://github.com/VanRoy/spring-cloud-dashboard),顺便说一句,这是一个很棒的前端。因此,当服务启动时,我们会看到它发现并检索正确的配置文件并加载它。在我进入spring云控制台并看到UP设置后,这意味着它通过发现被发现和注册。还有第二个状态指示器,即弹簧云仪表板获取已注册的端点并获得健康状态。在我的问题中,端点显示为UNKNOWN。

如果我然后使用显示在控制台中的端点并尝试信息执行器端点,则请求超时。这是我的问题的本质

好的,问题是什么?

基本上,因为我在application.yml中定义了,并且因为当服务在bootstrap中注册时它还不知道端口然后它选择默认值8080(我的假设,因为它就是这样)。服务器端口在application.yml中设置为9001但发现注册为8080,因此spring cloud控制台无法访问localhost:8080 / bookmarkservice / manage / health,因为该端点没有服务(实际上是9001) 。其他服务也找不到服务。

通过将server.port移动到bootstrap.yml,然后注册了速率服务的正确端点,并且可以正确访问该服务。