spring-cloud / spring-cloud-config

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

Combine eureka and config server,client cant use discovery #695

Closed SixPenny closed 6 years ago

SixPenny commented 7 years ago

Hi there ,I combined eureka \@EnableEurekaServer and config server \@EnableConfigServer in one class.I also add \@EnableDiscoveryClient annotation on it.But on the register page ,only registry is shown registered,without config-server.When I use config.discovery.enabled=true in client side,an error occurred that 'could not locate PropertySource and the fail fast property is set,failing'.Is there a method to handle this without split eureke and config server?

part of server application.yml

eureka:
    env: prod
    instance:
        hostname: localhost
        appname: registry
        prefer-ip-address: true
    server:
        # see discussion about enable-self-preservation:
        # https://github.com/jhipster/generator-jhipster/issues/3654
        enable-self-preservation: false
    client:
        fetch-registry: true
        register-with-eureka: true
        service-url:
            defaultZone: http://admin:${security.user.password:admin}@localhost:8761/eureka/

part of client bootstrap.yml

eureka:
    instance:
        prefer-ip-address: true
    client:
        service-url:
            defaultZone: http://admin:${jhipster.registry.password}@localhost:8761/eureka/

spring:
    cloud:
        config:
            fail-fast: true
            retry:
                initial-interval: 1000
                max-interval: 2000
                max-attempts: 100
#            uri: http://admin:${jhipster.registry.password}@eureka-peer-1:8761/config
            # name of the config server's property source (file.yml) that we want to use
            name: MamsGateway
            profile: prod # profile(s) of the property source
            label: master # toggle to switch to a different version of the configuration as stored in git
            discovery:
                enabled: true
                service-id: config-server
            # it can be set to any label, branch or commit of the config source git repository

ps:when I use spring.cloud.config.uri not discovery property ,it can locate config server.

ryanjbaxter commented 7 years ago

Can you provide a sample that reproduces the problem?

SixPenny commented 7 years ago

I generate my project using jhipster. Registry was downloaded. I uploaded all of it on https://github.com/SixPenny/SpringCloud.git under project folder. You can start registry with profile dev,peer1 and dev,peer2(run JHipsterRegistry twice, only one seems problem). Then start up service project, it'll report propertysource error. If you start ConfigServer project(removed @EnableEurekaServer annotation, the same with registry project) before service project, it starts fine.

spencergibb commented 7 years ago

You need to change the root of the config server since, by default it would take over the paths expected by eureka server.

On the server spring.cloud.config.server.prefix=/myprefix and spring.cloud.config.uri=http://<configserverhostport/myprefix on the client.

SixPenny commented 7 years ago

@spencergibb I did this in my project. I use the property spring.cloud.config.uri with prefix config now. Eureka also has eureka prefix. It works fine. But when I delete this and change to spring.cloud.config.discovery , it said 'cannot location config server'.

xiangyq000 commented 6 years ago

@SixPenny You can fix this problem by setting eureka.instance.metadata-map.configPath={spring.cloud.config.server.prefix} on the config server, thus all the config clients can know that prefix via service discovery and reach the config server endpoints with it. See discovery-first-bootstrap

sadunsamintha commented 6 years ago

Could you please tell clearly how do we Connect to Config Service from Config client via Eureka ?

this is the bootsrap.ym. file,

spring: application: name : mtx-buyer cloud: config: discovery: enabled: true serviceId : mtx-config-server failfast: true retry: maxAttempts: 100 initialInterval: 2000 maxInterval: 3000 multiplier: 1.5

eureka: client: register-with-eureka: true fetch-registry: false serviceUrl: defaultZone: http://172.17.0.1:1112/eureka/ healthcheck: enabled: true

logging: level: org.springframework.web: 'DEBUG'

ryanjbaxter commented 6 years ago

Please see our documentation http://cloud.spring.io/spring-cloud-static/Finchley.RELEASE

marcingrzejszczak commented 6 years ago

Please learn how to properly format the code