日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

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

發布時間:2024/4/14 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot b2b2c 多用户商城系统(八):配置中心服务化和高可用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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/dev、http://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 多用户商城系统(八):配置中心服务化和高可用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。