server端改造

1、添加依赖

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency>
</dependencies>复制代码

需要多引入spring-cloud-starter-eureka包,来添加对eureka的支持。

2、配置文件

server:
server:port: 8001
spring:application:name: spring-cloud-config-servercloud:config:server:git:uri: https://github.com/ityouknow/spring-cloud-starter/     # 配置git仓库的地址search-paths: config-repo                             # git仓库地址下的相对地址,可以配置多个,用,分割。username: username                                        # git仓库的账号password: password                                    # git仓库的密码
eureka:client:serviceUrl:defaultZone: http://localhost:8000/eureka/   ## 注册中心eurka地址复制代码

增加了eureka注册中心的配置

3、启动类

启动类添加@EnableDiscoveryClient激活对配置中心的支持

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

这样server端的改造就完成了。先启动eureka注册中心,在启动server端,在浏览器中访问:http://localhost:8000/就会看到server端已经注册了到注册中心了。

按照上篇的测试步骤对server端进行测试服务正常。

客户端改造

1、添加依赖

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>复制代码

需要多引入spring-cloud-starter-eureka包,来添加对eureka的支持。

2、配置文件

spring.application.name=spring-cloud-config-client
server.port=8002spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=spring-cloud-config-servereureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/复制代码

主要是去掉了spring.cloud.config.uri直接指向server端地址的配置,增加了最后的三个配置:

  • spring.cloud.config.discovery.enabled :开启Config服务发现支持
  • spring.cloud.config.discovery.serviceId :指定server端的name,也就是server端spring.application.name的值
  • eureka.client.serviceUrl.defaultZone :指向配置中心的地址

这三个配置文件都需要放到bootstrap.properties的配置中

3、启动类

启动类添加@EnableDiscoveryClient激活对配置中心的支持

@EnableDiscoveryClient
@SpringBootApplication
public class ConfigClientApplication {public static void main(String[] args) {SpringApplication.run(ConfigClientApplication.class, args);}
}复制代码

启动client端,在浏览器中访问:http://localhost:8000/ 就会看到server端和client端都已经注册了到注册中心了。

高可用

为了模拟生产集群环境,我们改动server端的端口为8003,再启动一个server端来做服务的负载,提供高可用的server端支持。

如上图就可发现会有两个server端同时提供配置中心的服务,防止某一台down掉之后影响整个系统的使用。

我们先单独测试服务端,分别访问:http://localhost:8001/neo-config/devhttp://localhost:8003/neo-config/dev返回信息:

{"name": "neo-config", "profiles": ["dev"], "label": null, "version": null, "state": null, "propertySources": [{"name": "https://github.com/ityouknow/spring-cloud-starter/config-repo/neo-config-dev.properties", "source": {"neo.hello": "hello im dev"}}]
}复制代码

说明两个server端都正常读取到了配置信息。

整体架构如下:

完整项目的源码来源

Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六

转载于:https://juejin.im/post/5c6a62a36fb9a049f23d5073

SpringBoot b2b2c 多用户商城系统(八):配置中心服务化和高可用相关推荐

  1. SpringBoot b2b2c 多用户商城系统 ssm b2b2c

    来源: SpringBoot b2b2c 多用户商城系统 ssm b2b2c 用java实施的电子商务平台太少了,使用spring cloud技术构建的b2b2c电子商务平台更少,大型企业分布式互联网 ...

  2. [菜鸟SpringCloud实战入门]第七章:配置中心客户端主动刷新机制 + 配置中心服务化和高可用改造...

    前言 欢迎来到菜鸟SpringCloud实战入门系列(SpringCloudForNoob),该系列通过层层递进的实战视角,来一步步学习和理解SpringCloud. 本系列适合有一定Java以及Sp ...

  3. (八)JAVA springcloud ssm b2b2c多用户商城系统源码:配置中心服务化和高可用

    server端改造 1.添加依赖 <dependencies><dependency><groupId>org.springframework.cloud</ ...

  4. java B2B2C 源码 多级分销springmvc mybatis多租户电子商城系统--配置中心服务化和高可用...

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.电子商务平台源码请加企鹅求求:一零三八七七四六二六. 这样就存在了一个问题,客户端和服务端的耦合性太高,如果server ...

  5. springcloud(八):配置中心服务化和高可用

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...

  6. SpringBoot b2b2c 多用户商城系统 (一)构建第一个SpringBoot工程

    简介 spring boot 它的设计目的就是为例简化开发,开启了各种自动装配,你不想写各种配置文件,引入相关的依赖就能迅速搭建起一个web工程.它采用的是建立生产就绪的应用程序观点,优先于配置的惯例 ...

  7. SpringBoot b2b2c 多用户商城系统(十五)Springboot整合RabbitMQ...

    这篇文章带你了解怎么整合RabbitMQ服务器,并且通过它怎么去发送和接收消息.我将构建一个springboot工程,通过RabbitTemplate去通过MessageListenerAdapter ...

  8. SpringBoot b2b2c 多用户商城系统

    由于业务量与日俱增,在今年产品业务线表已经有2000多张,可以想象业务之复杂.以及工程之多. 几乎每周都有新项目需要成立,原来的ssm.ssh架构搭建太繁琐,于是转换到SpringBoot上面来. 并 ...

  9. 小象电商是采用JAVA开发的B2B2C多用户商城系统。

    简介: 小象电商是采用JAVA开发的B2B2C多用户商城系统.以"平台自营+多商户入驻"为主要经营模式,可快速帮客户打造类似"京东"一样的自营+招商入驻的经营模 ...

最新文章

  1. Convolutional-MLPs改造
  2. Joomla2.5 JDate 时区日期运算
  3. IOS开发高级之点餐系统的实现-01
  4. 什么是框架?spring mvc框架
  5. jquery版相片墙(鼠标控制图片聚合和散开)
  6. 投资快手近尾声 腾讯持股超30%将置入资产或资源
  7. 陈正康考研英语长难句 51~75
  8. 微软:PowerShell 命令行工具存在 RCE 漏洞,请尽快修复
  9. mac 下chrome 和 微信web开发工具跨域配置
  10. python setup_简述python setup.py install的过程
  11. Atitit 提升可读性 流畅接口 1.1. 大接口vs 小接口 小接口可用流畅api串接起来 1 1.2. 部分comm fun可用大接口固化 1 2. 流畅接口 方法连 “Fluent接口
  12. 基于深度学习的图像修复
  13. 异常与调试之SEH、UEH、VEH、VCH以及SEH的区别总结——简单好理解
  14. 《悲剧性选择》卡拉布雷西 epub+mobi+azw3
  15. [转]Go语言(Golang)的Web框架比较:gin VS echo
  16. 基于NRF24L01的CAN数据透传
  17. 前端初级学习阶段(3)
  18. 光遇服务器修复暴风眼刷新了吗,光遇暴风眼怎么进 光遇暴风眼刷新时间
  19. GBase 8a的SNMP Trap 告警
  20. 2015去哪儿网校园招聘笔试题:寻找字符串的差异

热门文章

  1. 应用虚拟化的五大理由
  2. Goldengate介绍
  3. 位图索引(bitmap index)冲突引起的TX锁争用
  4. 不让自己的应用程序在桌面的图标列表里启动显示的方法
  5. Charles调试Https Android
  6. C++和Java的属性访问和方法调用 效率比较
  7. 浅谈Docker:DockerLinux安装,镜像管理命令,镜像制作命令,容器管理命令,数据卷,DockerFile,Docker-compose
  8. Navicat工具里的empty table和truncate table的区别
  9. MYSQL数据库导入出错:#1046 - No database selected
  10. html中盒子模型立体结构图