复习单个项目手动刷新4.5

服务端刷新——直接告诉rabbitmq

客户端刷新

1.1 客户端刷新config-client-bus集群
1.1.1 pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agan.springcloud</groupId>
<artifactId>config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>config-client-bus</artifactId>
<name>config-client-bus</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1.1.1.1 bootstrap.properties
spring.application.name=config-client
server.port=9031
eureka.client.serviceUrl.defaultZone=http://user:123456@eureka1:8761/eureka/,http://user:123456@eureka2:8761/eureka/
#默认是hostname 注册,改成IP 注册
eureka.instance.perferIpAddress=true
#默认false,这里设置true,表示开启读取配置中心的配置
spring.cloud.config.discovery.enabled=true
#对应eureka中的配置中心serviceId,默认是configserver
spring.cloud.config.discovery.serviceId=config-server
#指定环境
spring.cloud.config.profile=dev
#git标签
spring.cloud.config.label=master
#springboot 默认开启了权限拦截 会导致 /refresh出现401,拒绝访问
management.security.enabled=false
spring.rabbitmq.host=192.168.10.17
spring.rabbitmq.port=5672
spring.rabbitmq.username=test
spring.rabbitmq.password=123456
spring.rabbitmq.virtualHost=/
1.1.1 启动类
package com.agan.book.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/\*\*
\* @author 阿甘 http://study.163.com/instructor/1016671292.htm
\* @version 1.0
\*/
@SpringBootApplication
@EnableEurekaClient
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
1.1.1 控制层TestController.java
package com.agan.book.config.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RefreshScope
public class TestController {
@Value("\${book.config}")
private String msg;
@RequestMapping("/test")
public String test(){
return this.msg;
}
}
1.1.1 测试复制项目建立端口号不同的集群,启动config-server



模拟post请求刷新9031


测试成功,rabbitmq自动刷新9032

1.1 服务端自动刷新——config-server-bus
1.1.1 pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agan.springcloud</groupId>
<artifactId>config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>config-server-bus</artifactId>
<name>config-server-bus</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1.1.1.1 application.properties
spring.application.name=config-server
server.port=9030
eureka.client.serviceUrl.defaultZone=http://user:123456@eureka1:8761/eureka/,http://user:123456@eureka2:8761/eureka/
#默认是hostname 注册,改成IP 注册
eureka.instance.perferIpAddress=true
#springboot 默认开启了权限拦截 会导致 /refresh出现401,拒绝访问
management.security.enabled=false
spring.cloud.config.server.git.uri=https://gitee.com/agan\_jiagou/config
#spring.cloud.config.server.git.username=
#spring.cloud.config.server.git.password=
spring.rabbitmq.host=192.168.10.17
spring.rabbitmq.port=5672
spring.rabbitmq.username=test
spring.rabbitmq.password=123456
spring.rabbitmq.virtualHost=/
启动类
package com.agan.book.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
/\*\*
\* @author 阿甘 http://study.163.com/instructor/1016671292.htm
\* @version 1.0
\*/
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
1.1.1 测试启动服务端config-server-bus,启动config-client-bus集群


修改配置文件

1.1.1 模拟post请求



1.1.1 指定局部刷新

暂时刷新a,观察没问题再全部刷新

指定刷新9031

效果


刷新用户,订单所有服务

|