博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud 2.x学习笔记:6、高可用的分布式配置中心(Greenwich版本)
阅读量:2388 次
发布时间:2019-05-10

本文共 4128 字,大约阅读时间需要 13 分钟。

1、复用服务注册中心

参考https://blog.csdn.net/chengyuqiang/article/details/90645498

spring.application.name=register-serverserver.port=8800eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:8800/eureka/

在这里插入图片描述

2、改造config-server

2.1 pom.xml

添加

org.springframework.cloud
spring-cloud-starter-netflix-eureka-client

完整的pom.xml

4.0.0
com.cntaiping.tpa
config-server
0.0.1-SNAPSHOT
jar
config-server
Demo project for Spring Boot
com.cntaiping.tpa
config
1.0-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-config-server
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-jdbc

2.2 application.yml

eureka:  client:    serviceUrl:      defaultZone: http://localhost:8800/eureka/spring:  profiles:    active: jdbc  application:    name: config-server  datasource:    url: jdbc:mysql://10.17.12.160:3306/config?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&serverTimezone=GMT%2B8    username: root    password: 123456    driver-class-name: com.mysql.jdbc.Driver  cloud:    config:      label: master      server:        jdbc: trueserver:  port: 8300spring.cloud.config.server.jdbc.sql: SELECT key1, value1 from config_properties where APPLICATION=? and PROFILE=? and LABEL=?

2.3 Application启动类

添加@EnableEurekaClient

package com.cntaiping.tpa.configserver;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;@SpringBootApplication@EnableConfigServer@EnableEurekaClientpublic class ConfigServerApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigServerApplication.class, args);    }}

2.4 启动两个实例

在这里插入图片描述

在这里插入图片描述

3、改造config-client

3.1 pom.xml

4.0.0
com.cntaiping.tpa
config-client
0.0.1-SNAPSHOT
jar
config-client
Demo project for Spring Boot
com.cntaiping.tpa
config
1.0-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client

3.2 bootstrap.properties

spring.application.name=config-clienteureka.client.serviceUrl.defaultZone=http://localhost:8800/eureka/spring.profiles.active=dev#spring.cloud.config.uri= http://localhost:8300/spring.cloud.config.fail-fast=truespring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=config-serverserver.port=8083

3.3 Application类

package com.cntaiping.tpa.configclient;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClient@EnableDiscoveryClientpublic class ConfigClientApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigClientApplication.class, args);    }}

在这里插入图片描述

3、运行效果

在这里插入图片描述

在这里插入图片描述

你可能感兴趣的文章
使用FEC改善UDP(RTP)音视频传输效果
查看>>
RTP报文头部分析
查看>>
RTSP - RTP over TCP
查看>>
git将本地的仓库关联到github上
查看>>
RTSP协议详解
查看>>
使用TCP负载RTP
查看>>
团队协作工具的选择
查看>>
解决 win10家庭中文版 远程连接:出现身份验证错误 要求的函数不受支持
查看>>
浅析依赖倒置(DIP)、控制反转(IOC)和依赖注入(DI)
查看>>
C# 匿名函数引用局部变量解析
查看>>
完美解决 error C2220: warning treated as error - no object file generated
查看>>
WebRTC中的信令协议
查看>>
官网关于GridFS操作的说明文档
查看>>
ObjectMapper忽略未知字段
查看>>
Debezium
查看>>
nginx中配置ssl双向认证详解
查看>>
Debezium引擎
查看>>
ubuntu16.04下安装配置coturn
查看>>
Apache Traffic Control介绍
查看>>
OpenPGP Integration (Java and JavaScript)
查看>>