1

I would like to ask two questions about the Spring Cloud Config.

1) Is it possible to do an implementation of Spring Cloud Config Server to recover the properties of a base mongodb instead of git?

2) The Spring Cloud Config Client Setup automatically update when you have a change in ownership in Spring Cloud Config Server?

Thanks!!!

André Justi
  • 71
  • 1
  • 2
  • 7

4 Answers4

3

Spring Cloud Config Server MongoDB is now available on Github.

To get it up and running all you need to do is add the maven config as below, add @EnableMongoConfigServer to your Spring Boot application configuration and configure desired spring.data.mongodb.* properties.

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server-mongodb</artifactId>
        <version>0.0.1.BUILD-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>ojo-snapshots</id>
        <name>OJO Snapshots</name>
        <url>https://oss.jfrog.org/artifactory/libs-snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Then you can add configuration documents to MongoDB like this:

db.appname.insert({
   "label": "master",
   "profile": "prod",
   "source": {
        "user": {
            "max-connections": 1,
            "timeout-ms": 3600
        }
    }
});

And access them via http://localhost:8080/master/appname-prod.properties to obtain a response like this:

user.max-connections: 1.0
user.timeout-ms: 3600.0

UPDATE We have upgraded spring-cloud-config-server-mongodb to use spring-boot 1.5.7 snapshots.

Venil Noronha
  • 41
  • 1
  • 6
1
  1. Yes, it is possible, pull requests are welcome
  2. There is no push, but you can use spring's @Scheduled to call RefreshEndpoint.refresh() on an interval basis.
spencergibb
  • 24,471
  • 6
  • 69
  • 75
  • First thanks for the reply, it comes to my two other doubts. ***1)*** How do I cancel the creation of the bean **ConfigServerConfiguration$GitRepositoryConfiguration** that error when I set up, since I will not use it like to cancel. ***2)*** How do I create a custom **EnvironmentRepository** in my mongodb case. – André Justi May 05 '15 at 00:11
  • See these two links for help: https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerConfiguration.java#L69-L79 and https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/SvnKitEnvironmentRepository.java Basically you run config server with a different profile that creates a bean of `EnvironmentRepository` like someone else did for svn. – spencergibb May 05 '15 at 13:53
1

Not sure about 1. For 2) You have spring-cloud-bus which can provide push notifications to all the clients automatically when you make a change in the config server. http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html

Following are needed: 1. RabbitMQ/ Redis running locally 2. Add this dependency in config server pom xml. Use Brixton.M5 build.

<parent>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-parent</artifactId>
      <!-- <version>Brixton.BUILD-SNAPSHOT</version> -->
      <version>Brixton.M5</version>
      <relativePath /> 
    </parent>
<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-monitor</artifactId>
        <scope>test</scope>
    </dependency>
     <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>

3. Use the bus dependency in addition to the spring-config-client dependencies you might already have:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

4. [POST]http://localhost:/monitor?path= - this should push notifications to the clients. Alternately you can use a github webhook to post automatically where there is a change in the file.

You can refer to the post here

Community
  • 1
  • 1
Swetha V
  • 300
  • 5
  • 16
0

1. I recommend this git projecto to do that: https://github.com/spring-cloud-incubator/spring-cloud-config-server-mongodb

2. First, after make all your changes, add the @RefreshScope tag to your rest controller if you don't have it, like this:

@RefreshScope
@RestController
class MessageRestController {
   @Value("${message:Hello default}")
    private String message;

    @RequestMapping("/message")
    String getMessage() {
        return this.message;
    }

Next you need send an empty HTTP POST to the client’s refresh endpoint like this:

http://localhost:8080/refresh

note: you can use RESTclient plugin or POSTMAN in your browser to do that.

Finally probe the new message after a few seconds http://localhost:8080/message

note: this example is for client by default configuration...

Anthony Piñero
  • 616
  • 5
  • 10