Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-cloud random port not registered to Eureka

I'm trying to get my microservices to come up on random ports. If I specify server.port: 0 in the service bootstrap.yml as suggested in Spring Cloud app doesn't register correct port to Eureka I get the following NPE:

    2015-04-14 16:24:34,357  INFO          com.fisc.restmocker.Application:  47 - Starting Application on JSR-IAAS-20 with PID 4820 (C:\iaas2.0\git\FII-RestMocker\build\classes\main started by jsr in C:\iaas2.0\git\FII-RestMocker)
    2015-04-14 16:24:34,482  INFO ation.AnnotationConfigApplicationContext: 510 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4fb61f4a: startup date [Tue Apr 14 16:24:34 EDT 2015]; root of context hierarchy
    2015-04-14 16:24:34,748  INFO ion.AutowiredAnnotationBeanPostProcessor: 153 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    2015-04-14 16:24:35,217  WARN ix.config.sources.URLConfigurationSource: 120 - No URLs will be polled as dynamic configuration sources.
    2015-04-14 16:24:35,560  INFO ontext.support.DefaultLifecycleProcessor: 341 - Starting beans in phase 0
    2015-04-14 16:24:35,560  INFO lientConfigServiceBootstrapConfiguration:  92 - Locating configserver via discovery
    2015-04-14 16:24:35,592  WARN lientConfigServiceBootstrapConfiguration: 113 - Could not locate configserver via discovery
    java.lang.NullPointerException: null
        at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>) ~[spring-core-4.1.5.RELEASE.jar:1.1.147]
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) ~[spring-aop-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at com.netflix.discovery.DiscoveryClient$$EnhancerBySpringCGLIB$$96b726d7.getNextServerFromEureka(<generated>) ~[spring-core-4.1.5.RELEASE.jar:1.1.147]
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:93) [spring-cloud-netflix-core-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.onApplicationEvent(DiscoveryClientConfigServiceBootstrapConfiguration.java:65) [spring-cloud-netflix-core-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:1) [spring-cloud-config-client-1.0.0.RELEASE.jar:1.0.0.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:285) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE]
        at com.fisc.restmocker.Application.main(Application.java:18) [main/:na]
    2015-04-14 16:24:35,592  INFO          com.fisc.restmocker.Application:  56 - Started Application in 1.641 seconds (JVM running for 2.978)

Here is the bootstrap.yml:

    info:
      description: FII user interface mock service

    spring:
      application:
        name: FII-rest-mocker
      cloud:
        config:
          failFast: true
          discovery:
            enabled: true
            serviceId: config-server
          username: user
          password: password

    logging:
      level:
        com.netflix.discovery: 'OFF'
        org.springframework.cloud: 'DEBUG'

    eureka:
      instance:
        leaseRenewalIntervalInSeconds: 10
        metadataMap:
          instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
      client:
        serviceUrl:
          defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/

    server:
      port: 0

If I remove the server.port from the bootstrap.yml and place it in fii-rest-mocker.yml inside the configuration server, then my service starts up on a random port, but is registered on 8080 in Eureka.

I am only running one Eureka server and one Config server. All services are running on the same machine.

So, how does one get a service to boot and register in Eureka on a random port?

I'm using the 1.0.0.RELEASE version of spring-cloud and 1.2.2.RELEASE of spring-boot.

like image 731
user3537621 Avatar asked Apr 14 '15 21:04

user3537621


1 Answers

Random ports are not compatible with spring.cloud.config.discovery.enabled: true at the moment.

like image 82
spencergibb Avatar answered Oct 19 '22 22:10

spencergibb