springcloud学习2

一、运行配置服务器
1、启用配置服务器
创建一个Config Server项目
①pom.xml引入依赖:

  <dependency>
  <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-config-server</artifactId>
   </dependency>

pom.xml,如:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>config-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config-server</name>
    <description>Demo project for Spring Cloud</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>

②将@EnableConfigServer放到主类中,如:

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

③在application.yml中配置:

server:
  port: 8888		# 配置客户端服务中心必须要与其匹配

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/pathto/myapplication-config		# git 仓库地址。即可。

上面编写的配置是针对Config Server本身。与Config Server对外提供的配置是不同的。Config Server会对外提供Git或Vault获取到的配置信息。

现在还没有ConfigServer 客户端,用curl命令模拟一个客户端:

$ curl localhost:8888/application/default
{
 "name": "application",
 "profiles": [
	 "default"
 ],
 "label": null,
 "version": "aqbade15qwbgte0cqwerfvece4erfv2zaqsd",
 "state": null,
 "propertySources": []
}

会向Config Server的“application/default”路径发送Http GET请求。请求分为两部分或者3部分组成,如:

http://localhost:8888/application/default/master	

Config Server对外暴露了一个REST API(通过它可以消费配置属性)
其中,

localhost:8888是代表Config Server的主机和端口;
application表示应用的名称;现在没有特定应用的配置,所以任意值都是可以的。
default表示处于激活状态的Spring profile;目前没有特定profile的配置,所以任意的profile值都是可以的。
master表示Git标签/分支(可选)。指定了提供配置信息的后端Git仓库的标签或分支。如果没有指定,那么默认会用“master”分支。

可以看到,现在Property Sources属性是空的。需要为Git仓库填充Config Server要对外提供的属性。

2、填充配置仓库
有几种方法可以为Config Server设置属性。最基本、直接的方法是将application.properties或application.yml文件提交到Git仓库的根路径中。
如推送一个application.yml文件到根路径下:
application.yml:

server:
 port: 0
eureka:
 client:
  service-url:
   defaultZone: http://eureka1:8761/eureka/

注:当我们将服务变成Config Server客户端时,可以从服务中移除显示的Eureka配置。
作为Config Server的客户端,可以使用curl命令行查看Config Server提供的新配置数据:
如:

$ curl localhost:8888/someapp/someconfig
{
 "name": "someapp",
 "profiles": [
	 "someconfig"
 ],
 "label": null,
 "version": "95df0cbc3bca106199bd804b27a1de7c3ef5c35e",
 "state": null,
 "propertySources": [
	 {
		 "name": "http://localhost:10080/pathto/myapplication-config/application.yml",
		 "source": {
			 "server.port": 0,
			 "eureka.client.service-url.defaultZone": 
			"http://eureka1:8761/eureka/"
			 }
	 }
 ]
}

这个响应中,propertySources属性有值。 其中name属性指向了Git仓库的引用,source则包含了我们推送至Git仓库中的属性。
1)从Git子路径下提供配置

spring.cloud.config.server.git.search-paths 属性,让Config Server不再从根目录而是从"/config"目录下提供配置信息。

application.yml:

spring:
  cloud:
	config:
	  server:
	    git:
	      uri: http://localhost:10080/pathto/myapplication-config
	      search-paths: config

spring.cloud.config.server.git.search-paths可以让Config Server提供来自多个路径的配置。只需将它们逗号分隔即可:

spring:
 cloud:
   config:
     server:
       git:
         uri: http://localhost:10080/pathto/myapplication-config
         search-paths: config,moreConfig

还可以使用通配符来指定搜索路径:

spring:
  cloud:
    config:
      server:
        git:
          uri: http://localhost:10080/pathto/myapplication-config
          search-paths: config,more*

Config Server会提供来自“/config”和所有以“more”开头的子目录的配置。
2)从Git分支或标签下提供配置

 spring.cloud.config.server.git.default-label

application.yml:

spring:
  cloud:
    config:
      server:
        git:
          uri: http://localhost:10080/pathto/myapplication-config
          default-label: sidework

按照这个配置,出发Config Server客户端指定,否则将会提供“sidework”分支下的配置。
3)为Git后端提供认证
用户名:

spring.cloud.config.server.username

密码:

 spring.cloud.config.server.password

application.yml:

spring:
  cloud:
    config:
 	  server:
 	    git:
 		  uri: http://localhost:10080/pathto/myapplication-config
		  username: mydemotestuser
	      password: sa123Qsdfadsd

二、消费共享配置
Spring Cloud Config Server 提供了一个客户端库。它会包含在Spring Boot应用的构建文件中,允许应用成为Config Server的客户端。
将Spring Boot应用变成Config Server客户端的简单方式是添加依赖,如:

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

当应用启动的时候,自动配置功能将会自动化地注册一个属性源,该属性源将会从Config Server中拉取属性。默认情况,会假定Config Server运行在localhost并监听8888端口。如果不是,可以通过设置spring.cloud.config.uri 配置Config Server的位置。
application.yml:

spring:
  cloud:
    config:
       uri: http://config.mydemo.com:8888

当应用启动的时候,Config Server客户端提供的属性源将会对Config Server发送请求。接收到的属性将会放到应用的环境之中。此外,这些属性还会被缓存起来。
三、提供特定应用和profile的属性
1、提供特定应用的属性
使用Config Server可以让应用中的微服务共享通用的配置属性。除了共享配置之外,Config Server还能管理面向特定应用的配置属性。要实现这一点,需要将配置文件的名称命名为该应用spring.application.name属性的值。
可以在每个服务的spring.application.name属性中指定它的名称。然后根据各个服务的名称在Config Server的Git后端创建对应的配置YAML文件。
如:有多个微服务, ingredient-service, order-service, tacoservice, 和user-service

在Git后端建立对应的yml文件:ingredient-service.yml, order-service.yml, taco-service.yml, 和user-service.yml
如:

application.yml
ingredient-service.yml
order-service.yml
taco-service.yml
user-service.yml
注:不管服务应用的名称是什么,所有的应用都会接收来自application.yml文件的配置。

特定应用于application.yml的配置属性优先级:
如果application.yml中通用的属性与特定应用配置文件中的属性相同。那么特定应用的配置文件中属性会优先生效。
2、提供来自profile的属性
Spring Cloud Config Server支持特定于配置文件的属性,其方式与在单个Spring Boot应用程序中使用它们的方式完全相同。
如:

提供特定profile的.properties或YAML文件,例如名为application-production.yml的配置文件。
在单个YAML文件中提供多个profile配置组,以---和spring.profiles分隔开。

如application-production.yml:

server:
  port: 8080
 
eureka:
  client:
    service-url:
      defaultZone: http://eureka1:8761/eureka/,http://eureka2:8761/eureka/
application.yml
application-production.yml
ingredient-service.yml
order-service.yml
taco-service.yml
user-service.yml

在应用从Config Server获取配置信息的时候,Config Server会识别哪个profile处于激活状态(位于请求路径的第二部分)。
如果活跃profile是production。那么属性集(application.yml和application-production.yml)都会返回,并且application-production.yml中的属性会优先于application.yml中的默认属性。
这样的命名约定也适用于特定应用且特定profile的属性,也就是将属性文件命名为应用名+横线+profile名的形式。
如:
ingredient-service-production.yml,当production profile处于激活状态时,这些属性才有效。
properties文件也可同样的命名规则。
在YAML文件中,可以将特定profile 的属性和默认profile的属性放到同一个文件中。中间使用—,3个短横线和spring.profiles进行分割。

---
eureka:
  client:
    service-url:
      defaultZone: http://${other.eureka.host}:${other.eureka.port}/eureka
#     是否将自己注册到Eureka Server上,默认为true
#    register-with-eureka: false
#	 是否从Eureka Server上获取注册信息,默认为true
#    fetch-registry: false
spring:
  profiles: eureka-1
  application:
    name: eureka-server

server:
  port: 8761

eureka:
  instance:
    hostname: eureka1.learneurekademo.com

other:
  eureka:
    host: eureka2.learneurekademo.com
    port: 8762

---
spring:
  profiles: eureka-2
  application:
    name: eureka-server

server:
  port: 8762

eureka:
  instance:
    hostname: eureka2.learneurekademo.com

other:
  eureka:
    host: eureka1.learneurekademo.com
    port: 8761

四、保持配置属性的私密性
1、在Git中加密属性
在Config Server自己的配置中将encrypt.key属性设置为加密和解密密钥的值:

encrypt:
 key: s3123cr312t

这个属性要设置到bootstrap配置中(如,bootstrap.properties或bootstrap.yml)。这样,在自动配置功能启用Config Server之前,这个属性就会加载和启用。
为了更安全, 还可以使用keytool命令行工具:

keytool -genkeypair -alias tacokey -keyalg RSA \
-dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" \
-keypass s3123cr312t-keystore keystore.jks -storepass l3tm31n

这样形成的keystore会写入到keystore.jks的文件中。将这个keystore.jks文件放到文件系统或者放到应用本身。然后需要在ConfigServer的bootstrap.yml文件中配置keystore的位置和凭证信息。
为了在ConfigServer中使用加密,必须安装了Java Cryptography Extensions Unlimited Strength。
如果您选择将keystore打包到应用程序,将其放到类路径的根目录下。 配置属性的密钥存储库,让Config Server使用该keystore:

encrypt:
 key-store:
  alias: demokey
  location: classpath:/keystore.jks
  password: l3tm31n
  secret: s3123cr312t

在密钥和keystore配置好了后, 需要对某些数据进行加密。Config Server有一个/encrypt接口,我们提交一个Post请求到/encrypt接口,其中包括要加密的数据。如,连接MongoDB数控密码,借助curl:

$ curl localhost:8888/encrypt -d "sqwecr123123t"
qwe12a6412ght72vgfs7sdf6da234g12hyt8safa3523fs23gr2347

返回一个加密的值作为响应。然后把这个值,复制到Git仓库托管的配置文件中。
为了设置MongoDB,在Git仓库的application.yml文件添加 spring.data.mongodb.password属性:
application.yml

spring:
 data:
  mongodb:
   password: '{cipher}qwe12a6412ght72vgfs7sdf6da234g12hyt8safa3523fs23gr2347'

带有{cipher}前缀,告诉Config Server 这是一个加密 的值。
保存修改后,推送到Git仓库的application.yml中。
这样,ConfigServer就能对外提供加密的属性了。
curl模拟请求:

$ curl localhost:8888/application/default | jq
{
 "name": "app",
 "profiles": [
 	"prof"
 ],
 "label": null,
 "version": "dasuy534qw8asdgq235h36gfsfhrtdfa64d2123g43tf",
 "state": null,
 "propertySources": [
	 {
		 "name": "http://localhost:10080/path/to/myapplication-config/application.yml",
		 "source": {
		 	"spring.data.mongodb.password": "sqwecr123123t"
		 }
	 }
 ]
}

可以看到spring.data.mongodb.password的值是解密后的、默认情况下,Config Server 提供的所有加密值只是在后端Git仓库处于加密状态,在对外提供之前会解密。消费这个配置的客户端应用并不需要任何特殊的代码和配置就能接收Git已加密的属性。
2、在Vault中存储私密信息
HashiCorp Vault是私密管理工具。
1)启动Vault服务器
在使用Config Server写入和对外提供私密信息之前,需要先启动一个Vault服务。
简单方式在开发模式下使用如下命令启动服务器:

$ vault server -dev -dev-root-token-id=roottoken
$ export VAULT_ADDR='http://127.0.0.1:8200'
$ vault status

上面命令解析:
对Vault服务器服务器的所有访问权限都需要向该服务器提供一个token令牌。根token令牌是一个管理令牌,其中它还允许创建更多的其他token令牌。它也可以用来读取和写入私密信息。如果在开发模式下启动服务器时未指定根root令牌,则生成一个根令牌token并在启动时写入日志。这里的根token值设置成,如roottoken。
开发模式的服务器启动后,会监听本地机器的8200端口。设置VAULT_ADDR环境变量是很重要的,如上面的第二行命令。让vault命令行知道服务器在哪。
vault status 校验之前的命令是否按预期运行。
vault0.10.0版本或之后的版本,兼容Config Server

$ vault secrets disable secret
$ vault secrets enable -path=secret kv

2)写入私密信息到Vault中
将访问MongoDB的密码(spring.data.mongodb.password) 存储到Vault中,而不是存储到Git中。

$ vault write secret/application spring.data.mongodb.password=s12313c123r3t

上面命令行参数:

write 执行写入
secret 	“secret”后端
application 私密信息的路径
spring.data.mongodb.password 私密信息的key
s12313c123r3t私密信息的值

使用 vault read命令校验私密信息是否已经写入vault中:

$ vault read secret/application
Key 						 	Value
--- 						 	-----
refresh_interval 			 	768h
spring.data.mongodb.password 	s12313c123r3t

每次写入都会覆盖之前在该路径写入的私密信息。
如果想在Vault中写入MongoDB用户名,不能简单地写入spring.data.mongodb.username secret私密信息本身,因为这样会导致spring.data.mongodb.password 私密信息值丢失。所以要同时写入这2个属性:

% vault write secret/application \
 			  spring.data.mongodb.password=s12313c123r3t\
 			  spring.data.mongodb.username=appdemouser

3)在Config Server中启用Vault后端
将Vault添加为Config Server后端,至少需要将Vault添加为激活的profile。在Config Server的application.yml文件中,如:
application.yml:

spring:
 profiles:
 active:
 - vault
 - git

这样,vault和 git profile都处于激活状态,Config Server同时从vault和git获取配置。
默认情况下,Config Server会假定Vault运行在localhost并监听8200端口。也可以在Config Server的配置中修改默认行为,如:

spring:
 cloud:
  config:
  server:
  git:
   uri: http://localhost:10080/path/to/mywebsitedemo-config
   order: 2		# order 属性 设置优先级。这里vault高于git
  vault:
   host: vault.mywebsitedemo.com
   port: 8200
   scheme: https
   order: 1

现在用curl去模拟请求,会报错。因为请求中没有包含 vault token。

curl localhost:8888/application/default | jq

返回:


{
 "timestamp": "2018-01-29T13:23:21.215+0000",
 "status": 400,
 "error": "Bad Request",
 "message": "Missing required header: X-Config-Token",
 "path": "/application/default"
}

不会在Config Server本身中配置这个token,而是让每个Config Server客户端在向Config Server发送请求时包含X-Config-Token头信息。Config-Server会接收到X-Config-Token头信息,然后将其转换成发送给Vault的X-Vault-Token头信息。
4)在Config Server客户端设置vault token

spring:
 cloud:
  config:
   token: roottoken

spring.cloud.config.token属性告诉Config Server客户端在它向Config Server发出的所有请求中包含给定的令牌值。这个属性必须在应用程序的本地配置中设置(不能存储在ConfigServer的Git或Vault后端),以便ConfigServer将其传递给Vault,从而访问私密属性。
5)写入特定应用和特定profile的私密信息
当为Config Server提供服务时,写入application路径的属性适用所有应用程序,而不管它们的名称如何。 如果需要编写特定于给定应用程序的私密属性,就需要路径的application部分替换为应用的名称。 如,下面的vault write写命令将会名为ingredient-service的应用(由其spring.application.name属性指定)写入专有的私密信息:

$ vault write secret/ingredient-service spring.data.mongodb.password=s12313c123r3t

写入到特定的profile中,如:

$ vault write secret/application,production \
 			 spring.data.mongodb.password=s12313c123r3t\
 			 spring.data.mongodb.username=mywebsitedemouser

这将写入私密信息,这样它们将只对激活profile为production的应用有效。

五、在运行时刷新配置属性
Spring Cloud Config Server能够刷新正在运行的应用程序的配置属性,而不需要停机。一旦变更推送到支撑的Git仓库或者Vault私密仓库,应用中的每个微服务就都可以立即通过以下2种方式的某一种进行刷新。

手动刷新:Config Server在客户端启动一个特殊的“/actuator/refresh”端点,
对每个服务上的端点发送HTTP POST请求将强制配置客户端从Config Server的后端检索最新的配置。
自动刷新:Git仓库上提交钩子hook会触发Config Server客户端服务的属性操作。 这涉及Spring Cloud 的另一个项目Spring Cloud Bus,
它能够用于Config Server与其客户端之间的通信。

1、手动刷新配置属性
Actuator特性,只有配置为Spring Cloud Config Server客户端的应用,这个特性才有效。
当将应用设置为Config Server客户端的时候,自动配置功能会配置一个特殊的Acuator端点,用来刷新配置属性。为使用该端点,在项目构建文件中除了Config Client依赖,还要引入Actuator starter依赖:
引入依赖:
Actuator starter依赖

<dependency>
	 <groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

带有@ConfigurationProperties注解的类,
GreetingProps :

@ConfigurationProperties(prefix="greeting")
@Component
public class GreetingProps {
	 private String message;
	 public String getMessage() {
	 	return message;
	 }
	 public void setMessage(String message) {
	 	this.message = message;
	 }
}

控制器类:

@RestController
public class GreetingController {
  
  private final GreetingProps props;

  public GreetingController(GreetingProps props) {
    this.props = props;
  }

  @GetMapping("/hello")
  public String message() {
    return props.getMessage();
  }
  

在Git配置仓库有一个application.yml文件,有以下属性:

greeting:
 message: Hello World!

在应用启动运行起来后,对/hello 发送Http Get 请求,这里借助curl工具:

$ curl localhost:8080/hello

返回:

Hello World!

现在,对Config Server和 hello-world都不进行重启,而是修改application.yml文件并推送至后端Git仓库,这样greeting.message属性将会变成如下形式:

greeting:
 message: hello sunshine!

再次返回Get请求到 /hello接口。发现返回的结果还是Hello World!。
可以通过对刷新端点发送一个POST请求,强制使其更新:

$ curl localhost:53419/actuator/refresh -X POST

返回响应:

["config.client.version","greeting.message"]

响应中包含了一个json数组,列出了发生变更的属性名。包含config.client.version属性和greeting.message属性的变化。
再次发送请求/hello,

$ curl localhost:8080/hello

返回响应:

hello sunshine!

2、自动刷新配置属性
Config Server借助名为Spring Cloud Bus的Spring Cloud项目将配置变更自动通知到各个客户端。

刷新流程:

1.在配置Git存储库上创建一个webhook,对Git仓库的任何更改会通知Config Server。 许多Git实现都支持Webhooks,包括GitHub、GitLab、Bitbucket和Gogs。
2.Config Server会webhook POST请求做出响应,借助消息代理的(如Rabbit MQ或Kafka)广播来更改的。
3.每个Config Server客户端应用订阅该通知,对通知消息做出响应,也就是会使用Config Server中的新属性值刷新它们的环境。

这样的结果就是,在配置属性变更推送到后端的Git仓库后,所有的ConfigServer客户端应用能够立即获得最新的配置属性值。
在使用Config Server的自动刷新时,会有多个部件在发挥作用:

1.需要一个消息代理来处理Config Server与其客户端之间的消息传递。 可以选择Rabbit MQ或Kafka。
2.需要在后端Git仓库中创建一个webhook钩子,将各种变更通知给Config Sever。
3.Config Server需要启用Config Server监控依赖项(提供了处理来自Git仓库webhook请求的端点)以及Rabbit MQ
或Kafka Spring Cloud Stream依赖(用于发布属性更改消息给代理)。
4.除非消息代理在本地按照默认设置运行,否则要在Config Server及其所有客户端中配置连接到代理的详细信息。
5.每个Config Server客户端应用都需要Spring Cloud Bus依赖。

1)创建webhook
如配置/monitor 端点来处理这些请求。
配置后,每当仓库有推送,就向Config Server发送POST请求。
接下来,启用Config Server的 “/monitor”端点来处理这些请求。这里以Gogs为例。
2)在Config Server中处理webhook更新
添加spring-cloud-config-monitor依赖到Config Server的配置文件即可。在Maven的pom.xml,以下依赖就会完成该项工作。

<dependency>
	 <groupId>org.springframework.cloud</groupId>
	 <artifactId>spring-cloud-config-monitor</artifactId>
</dependency>

依赖添加完成之后,自动配置功能会发挥作用,从而启动“/monitor”端点。需要借助Spring Cloud Stream。它能够通过底层绑定机制通信的服务,这种通信机制可能是RabbitMQ或Kafka。服务在编写的时候并不会关心如何使用这些通信机制,只是接受流中的数据,对其进行处理,并返回到流中,由下游的服务继续处理。
“/monitor”端点使用Spring Cloud Stream发布通知消息给参与的Config Server客户端。为了避免硬编码特定的消息实现,监视器会作为Spring Cloud Stream的源,发布消息到流中并让底层的绑定机制处理消息发送的特定功能。
如果使用RabitMQ,就需要将Spring Cloud Stream RabbitMQ绑定依赖添加到Config Server的构建文件中:

<dependency>
	 <groupId>org.springframework.cloud</groupId>
	 <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>

如果使用Kafka,添加如下的Spring Cloud Stream Kafka依赖:

<dependency>
	 <groupId>org.springframework.cloud</groupId>
	 <artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>

依赖准备好了后,Config Server就可以参与属性自动刷新功能了。
如果前面配置都是默认值,没有修改,Config Server已经可以运行了。
如果要做修改,
application.yml重写默认值:

spring:
 rabbitmq:
  host: rabbit.mywebsitedemo.com
  port: 5672
  username: demoaccount
  password: s12313c123r3t

如果使用kafka,使用类似的属性:

spring:
 kafka:
 bootstrap-servers:
 - kafka.tacocloud.com:9092
 - kafka.tacocloud.com:9093
 - kafka.tacocloud.com:9094

3)创建Gogs的通知提取器,现Config Server已经支持Gogs
4)在Config Server的客户端中启用自动刷新
在Config Server客户端启用属性的自动刷新比Config Server本身更简单。需要添加依赖:

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

这样会添加AMQP(如RabitMQ)Spring Cloud Bus starter到构建文件中。
如果使用Kafka,就需要添加以下依赖:

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

对应的Spring Cloud Bus starter准备就绪后,启动应用的时候,自动配置功能就会发挥作用,应用会自动将自己绑定到本地运行的RabbitMQ代理或者Kafka集群上。
Config Server及其客户端都配置成了支持自动刷新。对application.yml做了修改,当将该文件提交至Git仓库时,会立即看到在客户端应用中生效。

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值