【发布时间】:2015-05-04 14:37:28
【问题描述】:
我想问两个关于Spring Cloud Config的问题。
1) 是否可以实现 Spring Cloud Config Server 来恢复基础 mongodb 而不是 git?
2)当您在 Spring Cloud Config ServerSpring Cloud Config Client 设置会自动更新/strong>?
谢谢!!!
【问题讨论】:
标签: java spring spring-cloud
我想问两个关于Spring Cloud Config的问题。
1) 是否可以实现 Spring Cloud Config Server 来恢复基础 mongodb 而不是 git?
2)当您在 Spring Cloud Config ServerSpring Cloud Config Client 设置会自动更新/strong>?
谢谢!!!
【问题讨论】:
标签: java spring spring-cloud
Spring Cloud Config Server MongoDB 现已在 Github 上提供。
要启动并运行它,您只需添加 maven 配置,如下所示,将 @EnableMongoConfigServer 添加到您的 Spring Boot 应用程序配置并配置所需的 spring.data.mongodb.* 属性。
<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>
然后你可以像这样向 MongoDB 添加配置文档:
db.appname.insert({
"label": "master",
"profile": "prod",
"source": {
"user": {
"max-connections": 1,
"timeout-ms": 3600
}
}
});
并通过http://localhost:8080/master/appname-prod.properties 访问它们以获得这样的响应:
user.max-connections: 1.0
user.timeout-ms: 3600.0
更新 我们已升级 spring-cloud-config-server-mongodb 以使用 spring-boot 1.5.7 快照。
【讨论】:
@Scheduled调用
RefreshEndpoint.refresh() 以间隔为基础。【讨论】:
EnvironmentRepository 的 bean,就像其他人为 svn 所做的那样。
不确定 1。 对于 2) 你有 spring-cloud-bus,当你在配置服务器中进行更改时,它可以自动向所有客户端提供推送通知。 http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
需要以下内容: 1.本地运行的RabbitMQ/Redis 2.在config server pom xml中添加这个依赖。使用 Brixton.M5 构建。
<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。除了您可能已经拥有的 spring-config-client 依赖项之外,还使用总线依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
4。 [POST]http://localhost:/monitor?path= - 这应该向客户端推送通知。或者,您可以使用 github webhook 在文件发生更改时自动发布。
您可以参考帖子here
【讨论】:
1. 我推荐这个 git projecto 来做到这一点:https://github.com/spring-cloud-incubator/spring-cloud-config-server-mongodb
2.首先,在进行所有更改后,如果您没有 @RefreshScope 标签,请将其添加到您的休息控制器,如下所示:
@RefreshScope
@RestController
class MessageRestController {
@Value("${message:Hello default}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
接下来,您需要向客户端的刷新端点发送一个空的 HTTP POST,如下所示:
http://localhost:8080/refresh
注意:您可以在浏览器中使用 RESTclient 插件或 POSTMAN 来执行此操作。
几秒后终于探测到新消息http://localhost:8080/message
注意:此示例是默认配置的客户端...
【讨论】: