Somnath
Somnath

Reputation: 83

Config server not getting discovered in a consul first setup

I am using a consul first setup. For this ,I am using a consul docker image with port 8500 mapped to 8500 so I can successfully use it on local set up.I can access consul at http://localhost:8500 .

I have the following configuration for the config server - pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-discovery</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.RC1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Application.yml

server:
   port: 8888
spring:
   cloud:
     config:
       server:
         git:
           uri: https://github.com/xxxxxx/spring-config-repo.git
consul:
  host: consul
  port: 8500
  enabled: true
  discovery:
    enabled: true
    register: true
    service-name: configservice

bootstrap.yml

spring:
   application:
     name: config-server

ConfigServerApplication.java

@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class ConfigServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServiceApplication.class, args);
    }
}

When I run this jar, it is successful. I can see the config server in consul ui. Following are the details of the config server as seen from consul-

Request - http://localhost:8500/v1/catalog/services
Response - 
{
"configservice": [],
"consul": []
}

Request - http://localhost:8500/v1/catalog/service/configservice
Response - 
[
 {
    "ID": "f6ac953c-07b9-4097-974e-3ea9cd39bec2",
    "Node": "a0954c644062",
    "Address": "127.0.0.1",
    "TaggedAddresses": {
        "lan": "127.0.0.1",
        "wan": "127.0.0.1"
    },
    "NodeMeta": {},
    "ServiceID": "config-server-8888",
    "ServiceName": "configservice",
    "ServiceTags": [],
    "ServiceAddress": "10.0.0.158",
    "ServicePort": 8888,
    "ServiceEnableTagOverride": false,
    "CreateIndex": 15,
    "ModifyIndex": 15
 }
]

I can also access the config server using this uri-

http://localhost:8888/configclient/default

I have client application which uses properties from the config server.My understanding is that when I run this jar, it will contact consul and get the config server information from there and populate the properties by fetching it from the given git uri.

Following are the details about the client - pom.xml

    <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-all</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.RC1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

bootstrap.yml

spring:
   application:
      name: myservice
cloud:
  config:
    fail-fast: true
    retry:
      max-attempts: 20
      initial-interval: 3000
   enabled: true
   discovery:
     enabled: true
     service-id: configserver
consul:
  host: localhost
  port: 8500
  discovery:
    enabled: true
    register: true
    service-name: myservice

application.yml

server:
   port: 8081

MyServiceApplication.java

@EnableDiscoveryClient
@SpringBootApplication
public class MyServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApplePaymentServiceApplication.class,    args);
    }
}

But during this startup of this jar, its not able to find the config server and instead falls back on the default uri . This is the relevant startup log section

2017-03-28 00:40:20.407  WARN 99123 --- [           main]  lientConfigServiceBootstrapConfiguration : No instances found of  configserver (configserver)


2017-03-28 00:40:20.551  INFO 99123 --- [           main]  b.c.PropertySourceBootstrapConfiguration : Located property source:   CompositePropertySource [name='consul', propertySources= . [ConsulPropertySource [name='config/myservice/'],   ConsulPropertySource [name='config/application/']]]
2017-03-28 00:40:20.587  INFO 99123 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2017-03-28 00:40:21.831  INFO 99123 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=myservice, profiles=[default], label=null, version=null, state=null
2017-03-28 00:40:21.832  INFO 99123 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/myservice.yml'], MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/application.yml']]]
2017-03-28 00:40:21.841  INFO 99123 --- [           main] c.h.MyServiceApplication       : No active profile set, falling back to default profiles: default 

I tinkered with a lot of different options from various examples such as consul first bootstrap with spring cloud config

Can someone point to what I might be missing ? Any pointers to a working example with access to proper application/bootstrap files for consul, configserver and client would be most helpful .

PS: I apologize for the information overload in the question. Some of it might not be relevant but I wanted to give as much information as possible so that someone can spot something that they have encountered before.

Upvotes: 0

Views: 2173

Answers (1)

spencergibb
spencergibb

Reputation: 25157

You're trying to look up configserver, but it is registered as configservice.

Upvotes: 2

Related Questions