spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

In Eureka First Bootstrap mode, config data wouldn't load if a client starts on a random port number #93

Open seeksong opened 9 years ago

seeksong commented 9 years ago

In Eureka First mode, if client starts on a random port (--server.port=0), the client code will ignore the Eureka setup and always try to load config data from default location (localhost:8888). In my case, I have config server runs on 8810, and the client bootstrap as,

spring.application.name=test-server
server.port=0

spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

eureka.client.serviceUrl.defaultZone=http://localhost:8020/eureka/
eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}

Here is the error when my client bootup,

2015-02-26 14:11:30.320 ERROR 21609 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/test-server/default/master":Connection refused; nested exception is java.net.ConnectException: Connection refused
dsyer commented 9 years ago

Does this have anything to do with server.port=0? Where is that configuration file (needs to be in bootstrap.properties)?

seeksong commented 9 years ago

from what i see, it does. if i specify a port numer in command line, everything works just fine. the config is in bootstrap.properties.

please let me know if you need more detail.

dsyer commented 9 years ago

Works for me. Here's the top of the log:

2015-02-27 17:59:12.833  INFO 31498 --- [           main] demo.EurekaFirstApplication              : Starting EurekaFirstApplication on dsyer with PID 31498 (/home/dsyer/dev/cloud/scripts/tests/eureka-first/target/classes started by dsyer in /home/dsyer/dev/cloud/scripts/tests/eureka-first)
2015-02-27 17:59:12.912  INFO 31498 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6295d394: startup date [Fri Feb 27 17:59:12 GMT 2015]; root of context hierarchy
2015-02-27 17:59:13.137  INFO 31498 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-02-27 17:59:13.471  WARN 31498 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2015-02-27 17:59:13.471  INFO 31498 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2015-02-27 17:59:13.484  INFO 31498 --- [           main] c.netflix.config.DynamicPropertyFactory  : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@7c8c9a05
2015-02-27 17:59:13.798  INFO 31498 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2015-02-27 17:59:13.803  INFO 31498 --- [           main] .p.EurekaConfigBasedInstanceInfoProvider : Setting initial instance status as: STARTING
2015-02-27 17:59:14.418  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2015-02-27 17:59:14.420  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2015-02-27 17:59:14.421  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2015-02-27 17:59:14.421  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false
2015-02-27 17:59:14.421  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2015-02-27 17:59:14.421  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2015-02-27 17:59:14.563  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2015-02-27 17:59:14.626  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : The response status is 200
2015-02-27 17:59:14.631  INFO 31498 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 10
2015-02-27 17:59:14.645  INFO 31498 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application eurekafirst with eureka with status UP
2015-02-27 17:59:14.647  INFO 31498 --- [           main] lientConfigServiceBootstrapConfiguration : Locating configserver via discovery
2015-02-27 17:59:14.682  INFO 31498 --- [           main] demo.EurekaFirstApplication              : Started EurekaFirstApplication in 2.106 seconds (JVM running for 2.542)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.1.RELEASE)

2015-02-27 17:59:16.159  INFO 31498 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/spring-cloud-samples/config-repo/application.yml']]]
2015-02-27 17:59:16.191  INFO 31498 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@72ba28ee: startup date [Fri Feb 27 17:59:16 GMT 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@6295d394
...

I'm using the configserver-eureka and eureka-first samples here: https://github.com/spring-cloud-samples/tests. Maybe if you can share a minimal project that has this problem that would help?

seeksong commented 9 years ago

Thanks for looking at this. I will try to construct a mini project and get back to you soon

seeksong commented 9 years ago

ok, here is my project and logs for both random port and specific port (i am using java 8 if that matters),

  1. main class,
@Configuration
@EnableAutoConfiguration
public class MainEntry {
    public static void main(String[] args) {
        SpringApplication.run(MainEntry.class, args);
    }
}
  1. build file
ext {
    springCloudVersion = "1.0.0.RC3"
    //springCloudVersion = "1.0.0.BUILD-SNAPSHOT"
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE")
    }
}

apply plugin: 'spring-boot'

jar {
    baseName = 'config-client'
    version = '1.0'
}

repositories {
    mavenCentral()
    jcenter()
    maven{url "http://repo.spring.io/milestone"}
    maven{url "http://repo.spring.io/snapshot"}
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.cloud:spring-cloud-starter-parent:${springCloudVersion}")
    compile("org.springframework.cloud:spring-cloud-starter-eureka:${springCloudVersion}")
    compile("org.springframework.cloud:spring-cloud-config-client:${springCloudVersion}")
}
  1. bootstrap.properties
spring.application.name=config-client
server.port=0

spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

eureka.client.serviceUrl.defaultZone=http://localhost:8020/eureka/
eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
  1. run on random port ( java -jar config-client.jar )
2015-02-27 14:56:45.987  INFO 1914 --- [           main] app.MainEntry                            : Starting MainEntry on nuberdev5.corporate.local with PID 1914 (/home/qsong/Downloads/config-client/build/libs/config-client-1.0.jar started by qsong in /home/qsong/Downloads/config-client)                                                            
2015-02-27 14:56:46.078  INFO 1914 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1b7b8322: startup date [Fri Feb 27 14:56:46 MST 2015]; root of context hierarchy                                                                                   
2015-02-27 14:56:46.283  INFO 1914 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring                                                         
2015-02-27 14:56:46.727  WARN 1914 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.                                                                            
2015-02-27 14:56:46.727  INFO 1914 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.                                                                                   
2015-02-27 14:56:46.736  INFO 1914 --- [           main] c.netflix.config.DynamicPropertyFactory  : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@70756d57      
2015-02-27 14:56:47.085  INFO 1914 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0                                                                                                           
2015-02-27 14:56:47.086  INFO 1914 --- [           main] lientConfigServiceBootstrapConfiguration : Locating configserver via discovery                                                                                                 
2015-02-27 14:56:47.114  WARN 1914 --- [           main] lientConfigServiceBootstrapConfiguration : Could not locate configserver via discovery                                                                                         

java.lang.NullPointerException: null
        at com.netflix.discovery.DiscoveryClient$$FastClassBySpringCGLIB$$a84c8cb4.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)                   
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)                                                                                                                
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)                                                                                                      
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)                                                                                                         
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)                                                                                                                  
        at com.netflix.discovery.DiscoveryClient$$EnhancerBySpringCGLIB$$9b59026a.getNextServerFromEureka(<generated>)                                                                                                                  
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.onApplicationEvent(DiscoveryClientConfigServiceBootstrapConfiguration.java:68)                                                   
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.onApplicationEvent(DiscoveryClientConfigServiceBootstrapConfiguration.java:1)                                                    
        at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration$$EnhancerBySpringCGLIB$$e295c88b.onApplicationEvent(<generated>)                                                                 
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)                                                                                               
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)                                                                                               
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)                                                                                                             
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)                                                                                                            
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)                                                                                                                  
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)                           
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)                               
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)         
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125)                                                                                              
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75)                                                                                                    
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:55)                                                                                                    
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)                                                                                               
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)                                                                                               
        at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)                                                                                                          
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59)                                                                                                    
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:286)                               
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)                               
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)                               
        at app.MainEntry.main(MainEntry.java:12)                                                                    
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                              
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                            
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                    
        at java.lang.reflect.Method.invoke(Method.java:483)                                                         
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)                           
        at java.lang.Thread.run(Thread.java:745)                                                                    

2015-02-27 14:56:47.117  INFO 1914 --- [           main] app.MainEntry                            : Started MainEntry in 1.363 seconds (JVM running for 2.11)                                                                           

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / / 
 =========|_|==============|___/=/_/_/_/  
 :: Spring Boot ::        (v1.2.1.RELEASE)

2015-02-27 14:56:47.514 ERROR 1914 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/config-client/default/master":Connection refused; nested exception is java.net.ConnectException: Connection refused                                                
2015-02-27 14:56:47.520  INFO 1914 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@42f4a4e7: startup date [Fri Feb 27 14:56:47 MST 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1b7b8322   
  1. run on specific port (java -jar config-client --server.port=9900)
2015-02-27 15:02:22.339  INFO 2161 --- [           main] app.MainEntry                            : Starting MainEntry on nuberdev5.corporate.local with PID 2161 (/home/qsong/Downloads/config-client/build/libs/config-client-1.0.jar started by qsong in /home/qsong/Downloads/config-client)    
2015-02-27 15:02:22.429  INFO 2161 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1b7b8322: startup date [Fri Feb 27 15:02:22 MST 2015]; root of context hierarchy                           
2015-02-27 15:02:22.644  INFO 2161 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring                                                                                                                     
2015-02-27 15:02:23.064  WARN 2161 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.                                                                                                                                        
2015-02-27 15:02:23.065  INFO 2161 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.                           
2015-02-27 15:02:23.073  INFO 2161 --- [           main] c.netflix.config.DynamicPropertyFactory  : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@70756d57                                                                  
2015-02-27 15:02:23.570  INFO 2161 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0                     
2015-02-27 15:02:23.573  INFO 2161 --- [           main] .p.EurekaConfigBasedInstanceInfoProvider : Setting initial instance status as: STARTING  
2015-02-27 15:02:24.372  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false                
2015-02-27 15:02:24.373  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null   
2015-02-27 15:02:24.373  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false             
2015-02-27 15:02:24.373  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false                   
2015-02-27 15:02:24.373  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true   
2015-02-27 15:02:24.373  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true               
2015-02-27 15:02:24.483  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server                                                                                                                                       
2015-02-27 15:02:24.542  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : The response status is 200                    
2015-02-27 15:02:24.546  INFO 2161 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30                                                                                                                                              
2015-02-27 15:02:24.553  INFO 2161 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application config-client with eureka with status UP                                                                                                                                
2015-02-27 15:02:24.555  INFO 2161 --- [           main] lientConfigServiceBootstrapConfiguration : Locating configserver via discovery           
2015-02-27 15:02:24.583  INFO 2161 --- [           main] app.MainEntry                            : Started MainEntry in 2.494 seconds (JVM running for 3.104)                                                                                                                                      

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / / 
 =========|_|==============|___/=/_/_/_/  
 :: Spring Boot ::        (v1.2.1.RELEASE)

2015-02-27 15:02:25.287  INFO 2161 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='applicationConfig: [file:config-repo/application.properties]']]]              
2015-02-27 15:02:25.305  INFO 2161 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@de901cf: startup date [Fri Feb 27 15:02:25 MST 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1b7b8322      
spencergibb commented 9 years ago

@dsyer Because of the way EurekaDiscoveryClientConfiguration and random ports work, DiscoveryClient is null when DiscoveryClientConfigServiceBootstrapConfiguration.refresh() is run. I tried listening for InstanceRegisteredEvent but that didn't work. I think it's a parent/child context problem.

spencergibb commented 9 years ago

actually, I was able to get it to work, but I'm not sure of the ramifications.

spencergibb commented 9 years ago

so, refresh is called, but the config client isn't loading configuration

spencergibb commented 9 years ago

Yeah InstanceRegisteredEvent doesn't happen until after PropertySourceBootstrapConfiguration is done.

spencergibb commented 9 years ago

@seeksong A workaround would be to find an available tcp prior to running java and assign the value to SERVER_PORT. http://www.commandlinefu.com/commands/view/7299/find-an-unused-unprivileged-tcp-port

seeksong commented 9 years ago

thanks!

ciberado commented 9 years ago

Looks like this is a regression: using spring-boot-starter-parent:1.2.4.RELEASE on my web services everything is registered correctly basically because the call to the Eureka server is delayed a few seconds after the bootstrapping of the application.

If I change it to the 1.3.0RC the web service tries to register on Eureka just after starting, failing miserably in reporting the correct port.

dsyer commented 9 years ago

I think you are confused about versions (a bit), so for the sake of clarity: Spring Cloud Brixton.M2 comes with Spring Boot 1.3.0.RC1, and Angel.SR3 is Spring Boot 1.2.x. Presumably you tried one or the other. I believe at one point the Brixton release train was working with server.port=0, but it isn't in snapshots. Interestingly the EurekaDiscoveryClientConfiguration has the local.server.port in time and calls its start() method with the right values in place, but the service entry in Eureka is not updated.

ciberado commented 9 years ago

You are right, sorry. Actually the artifact that works for me is spring-cloud-starter-eureka-1.0.2 within a pom that has spring-boot-starter-parent:1.2.4.RELEASE as its parent.

dinkarthakur commented 8 years ago

I'm using spring cloud Brixton.M4 and spring boot is v1.3.1, with eureka first approach and application starts on random port server.port=0 but its register it self at port 0 with eureka server. here is my bootstrap.properties file

server.port=0

spring.application.name=course-composite-service

spring.cloud.config.fail-fast=true
spring.cloud.config.label=config-dev
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

eureka.client.serviceUrl.defaultZone=http://localhost:8002/eureka/

and below its the log

2016-01-11 18:36:50.286  INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0: registering service...
2016-01-11 18:36:50.288  INFO 17233 --- [           main] .w.c.c.CourseCompositeServiceApplication : Started CourseCompositeServiceApplication in 5.325 seconds (JVM running for 5.856)
2016-01-11 18:36:50.321  INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0 - registration status: 204

and eureka dashboard shows

COURSE-COMPOSITE-SERVICE        UP (1) - 192.168.17.178:course-composite-service:0

why its not registering with the actual port its running? i'm providing other eureka configurations from the Config Sever they are

eureka.client.register-with-eureka=true
eureka.instance.leaseRenewalIntervalInSeconds=10
eureka.instance.leaseExpirationDurationInSeconds=5
eureka.instance.preferIpAddress=false
eureka.instance.metadataMap.hostname=${vcap.application.application_uris[0]}
eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
Haybu commented 8 years ago

please help with my very simple case. following the steps, the config server is up on port 8888, pointing to a git repo with one of the config prop file named (reservation_service.properties). I'm able to hit the configuration at localhost:8888/reservation_service/default and see the configuration.

The other simple spring cloud config client, that includes the spring-cloud-starter-config dependency, and has the following in the bootstrap.properties file:

spring.application.name=reservation_service spring.cloud.config.uri=http://localhost:8888

when starting this application, I get:

2016-09-02 12:14:07.079 INFO 46315 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888 2016-09-02 12:14:07.149 WARN 46315 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 400 Bad Request 2016-09-02 12:14:07.150 INFO 46315 --- [ main] i.a.ReservationServiceApplication : No active profile set, falling back to default profiles: default

spencergibb commented 8 years ago

@Haybu your question doesn't seem like it relates to this issue. Please ask on stack overflow or gitter.

Haybu commented 8 years ago

Thanks @spencergibb. it works just now, for some reason port 8888 does want to work for my config server, I changed that to something different (8889) and that works.

acbenny commented 4 years ago

I'm using Hoxton.SR1 with consul discovery and the same issue seems to be there. The server gets initialised with a random port and starts fine but in consul, its registered with instance id as 0 picked from the server.port property. So a 2nd instance doesn't get registered as the instance id is already present.

There is a workaround by explicitly assigning the instance id with a random int but it would be good if the framework can pick up the actual port instead of the property value.

cerebrosoft commented 4 years ago

Yes still an issue on Hoxton with Eureka. At first I thought port 0 was being registered with Eureka, but it actually gets the correct port but the instanceId does not, which prevents additional instances from registering.

There are two workarounds: either force the instanceId to be unique:

instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}} or Use the workaround blogged about here: https://blog.joshmlwood.com/eureka-spring-cloud-random-port/. I suspect his fix works by changing the order of operations and timing enough to get around the bug.

The former requires no code changes but makes a bit of a mess of the instanceIDs. The latter keeps the instance IDs relevant but requires changes that otherwise shouldn't be necessary.

spencergibb commented 4 years ago

Setting the instance ID is currently the recommended way of working with random ports.