spring cloud config + bus + rabbitmq

一、config-server

1、pom配置

        <!--boot版本和cloud版本-->
        <spring.boot.version>2.1.5.RELEASE</spring.boot.version>
        <spring.cloud.version>Greenwich.SR2</spring.cloud.version>
	<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>
		<!-- springcloud-bus依賴實現配置自動更新,rabbitmq -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>
	</dependencies>

 2、bootstrap.yml配置

server:
  port: 8383
spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/bell-zhouxiaobing/spring-cloud/
          search-paths:
          - config-repo
          username: 
          password: 
    bus:
      trace:
        enabled: true
  rabbitmq:
    host: ip
    port: 5672
    username: username
    password: password
management:
  endpoints:
    web:
      exposure:
        include:
        - "*"
# 加密config配置文件,加密後的字符串前綴{cipher}
encrypt:
#  key: staginfo-config-key # 對稱加密密鑰
  key-store:
    alias: mytest
    password: mypass  # 設置store的密碼 
    location: classpath:mytest.jks
    secret: mypass  # mytest密碼
  
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

3、啓動類配置

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

二、config-client

1、pom配置 

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>
		<!-- config 依賴 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- config 依賴end -->

	</dependencies>

 

2、bootstrap.yml配置 

server:
  port: 8182
spring:
  application:
    name: user-consumer
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server
      # 開發環境
      profile: dev
      # 版本分支
      label: master
  rabbitmq:
    host: ip
    port: 5672
    username: username
    password: password
    
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

 3、啓動類配置

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

	@Value("${test}")
	private String test;
	
	@GetMapping("/hi")
	public String hi() {
		return test;
	}

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章