什么是Spring Boot配置以使用Cloud Foundry Service Registry(Netflix Eureka)服务?

时间:2017-03-25 16:02:36

标签: spring-boot cloudfoundry microservices netflix-eureka

我可以在本地设置我自己的Eureka服务器,并在没有任何问题的情况下注册我的服务,但是当我使用Pivotal Cloud Foundry的“Service Registry”服务创建Eureka服务器时,我的应用程序没有显示在“已注册的应用程序”下。

我做了以下事情:

  1. 通过Cloud Foundry Marketplace创建Service Registry。
  2. 将我的应用程序绑定到服务。
  3. 使用该服务成功注册了我的应用程序。
  4. 日志:

    2017-03-25T11:32:26.994-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:26.994 INFO 13 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.endpoint:name=refreshEndpoint,type=RefreshEndpoint]
    2017-03-25T11:32:27.426-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:27.424 INFO 13 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
    2017-03-25T11:32:27.444-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:27.443 INFO 13 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
    2017-03-25T11:32:27.758-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:27.755 INFO 13 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
    2017-03-25T11:32:27.758-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:27.758 INFO 13 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
    2017-03-25T11:32:28.114-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.113 INFO 13 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
    2017-03-25T11:32:28.114-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.113 INFO 13 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
    2017-03-25T11:32:28.682-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.678 INFO 13 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
    2017-03-25T11:32:28.745-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
    2017-03-25T11:32:28.745-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
    2017-03-25T11:32:28.745-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
    2017-03-25T11:32:28.746-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
    2017-03-25T11:32:28.746-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
    2017-03-25T11:32:28.747-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.745 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
    2017-03-25T11:32:28.761-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:28.747 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
    2017-03-25T11:32:29.156-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.155 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
    2017-03-25T11:32:29.160-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.160 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
    2017-03-25T11:32:29.165-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.164 INFO 13 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
    2017-03-25T11:32:29.170-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.169 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1490455949169 with initial instances count: 23
    2017-03-25T11:32:29.227-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.227 INFO 13 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application gym-service with eureka with status UP
    2017-03-25T11:32:29.230-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.229 INFO 13 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1490455949229, current=UP, previous=STARTING]
    2017-03-25T11:32:29.236-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.236 INFO 13 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GYM-SERVICE/3a2f6286-096c-4a2a-782a-03bab8f020a9: registering service...
    2017-03-25T11:32:29.349-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.348 INFO 13 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GYM-SERVICE/3a2f6286-096c-4a2a-782a-03bab8f020a9 - registration status: 204
    2017-03-25T11:32:29.570-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.569 INFO 13 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
    2017-03-25T11:32:29.575-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.574 INFO 13 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 8080
    2017-03-25T11:32:29.582-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:32:29.582 INFO 13 --- [ main] com.campbellonsoftware.orka.GymServer : Started GymServer in 22.159 seconds (JVM running for 24.923)
    2017-03-25T11:32:31.135-04:00 [CELL/0] [OUT] Container became healthy
    2017-03-25T11:37:28.751-04:00 [APP/PROC/WEB/0] [OUT] 2017-03-25 15:37:28.751 INFO 13 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
    

    manage-gym.yml文件:

    # Spring properties
    spring:
      application:
         name: gym-service  # Service registers under this name
      freemarker:
        enabled: false           # Ignore Eureka dashboard FreeMarker templates
      thymeleaf:
        cache: false             # Allow Thymeleaf templates to be reloaded at runtime
        prefix: classpath:/manage-gym/templates/    # Trailing / mandatory
                                 # Template location for this application only
    
    # Map the error path to error template (for Thymeleaf)
    error:
      path: /error
    
    # HTTP Server
    server: 
      port: 2222   # HTTP (Tomcat) port
    
    # Discovery Server Access
    #  1. DEV ONLY: Reduce the lease renewal interval to speed up registration
    #  2. Define URL of registration server (defaultZone)
    eureka:
      client:
        serviceUrl:
          defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:${eureka.password:}@${PREFIX:}eureka.${application.domain:cfapps.io}}/eureka/
      instance:
        hostname: ${vcap.application.uris[0]}
        leaseRenewalIntervalInSeconds: 30   # DO NOT DO THIS IN PRODUCTION
    

    主类:

    package com.campbellonsoftware.orka;
    
    import java.util.logging.Logger;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    
    @SpringBootApplication
    @EnableAutoConfiguration
    @EnableDiscoveryClient
    public class GymServer {
    
    
        protected Logger logger = Logger.getLogger(GymServer.class.getName());
    
        public static void main(String[] args) {
            System.setProperty("spring.config.name", "manage-gym");
            SpringApplication.run(GymServer.class, args);
        }
    }
    

    服务注册: Service Registry config

1 个答案:

答案 0 :(得分:1)

我认为服务注册表是一个预先设置的eureka服务器,就像我在本地运行的服务器一样,但事实并非如此。

它在幕后使用eureka,但完全是一个单独的过程,需要添加以下依赖项。

的pom.xml:

constructor(props: Props) {
  super(props);

  const self: Object = this
  self.handleSearchSubmit = this.handleSearchSubmit.bind(this)
}

结果: enter image description here